Monthly Archives: May 2015

ASP.NET 5, DNX, stepping into MS source code

One feature which I find awesome in ASP.NET 5/vNext is the ability to download MS source code and debug it locally (I discussed this here under the global.json section). This was discussed in several sessions with Scott Hanselman and demonstrated well with Damian Edwards (Deep Dive into ASP.NET 5 – approx minute 16:20 into the session). I find this feature great because there have been countless times that I tried to understand why .NET was behaving the way it does. Despite .NET source code being available for download and debug sometimes, it was hectic getting it to work and eventually I used reflection tools to read .NET assemblies and trying to understand why things are working (or not). So being able to simply download the code and using it locally sounds great.

However despite the session with Damien I still had problems getting it to work and Damian was kind enough to assist me where I had trouble. I assume that MS will make it easier in the future. On stage Scott and Damian discussed having a context menu option to “switch to source code”. Indeed it could be great, especially if that will also download the correct version of the source code – because that is mainly what was giving me trouble.

So here is a walk through (I used VS2015 RC):

  1. Create an ASP.NET 5 app using the template website.1
  2. Run it (F5), just in case to see that it works and that if you encounter errors in the process, they are not related to something else which is faulty.
  3. Download the correct tag of MVC from Github. Note: this is what fooled me. I initially downloaded the ongoing “dev” tag when I should have actually downloaded “6.0.0-beta4”. As you can see, you can tell the correct tag as it is specified in the Solution Explorer: 2Follow the steps in the image below:3
  4. Once downloaded and extracted, edit global.json in your solution and add the local path to the “projects” element. Note that the slashes have to be forward slashes. As soon as you click save you will witness the Solution Explorer going berserk as VS automatically loads the local source code. More importantly, you can see that the icon in VS for MVC has changed to that of local files.4
  5. Basically that’s it. You can now re-run the code and step through. Taking Damian’s example from Build 2015, I inserted the new <cache> tag and placed a breakpoint within the CacheTagHelper class.5

Once again, thanks Damian.

Leave a comment

Posted by on 31/05/2015 in Software Development


Tags: , ,