An Inside Look at ASP.NET 5 Execution – Setup for Debugging

On the previous post of this series we got to the point where DNX invokes ASP.NET code. While I already had DNX code on VS, I guess from now on it’ll be more important (fun?) to debug and see things happening, so I’ll recap the debug setup before moving further. I’ve cover this on part I and part II of the series but things are a bit fragmented. Also, I was based beta 4 releases of the different components; that was 2 months ago, so I’ll be moving into the latest versions (release branch versions, actually, which seem to be on beta 6 by now). So, here’s what I did:

git clone https://github.com/aspnet/Mvc.git -b release
  • Install DNVM using the command on GitHub or update the existing installation using:
dnvm update-self
  • Install the latest versions of DNX for CLR and CoreCLR (at the time of writing the version is beta6-11944):
dnvm upgrade -r clr -unstable
dnvm upgrade -r coreclr -unstable
  • Create an hello-world folder and add a Startup.cs file with the following content:
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using System;

namespace HelloWorld.Web
{
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.Run(ctx => ctx.Response.WriteAsync("Hello ASP.NET 5 world! Time: " + DateTime.Now));
}
}
}
  • On the same folder add a project.json file with the following content:
{
"webroot": "wwwroot",
"dependencies": {
"Microsoft.AspNet.Hosting": "1.0.0-beta-*",
"Microsoft.AspNet.Mvc": "6.0.0-beta-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta-*"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
}
}
  • Open a command line on the folder and run:
dnu restore
dnx . web

This should launch the server. Try navigating to the URL configured on the project file. Then:

  • Open VS 2015 and create a blank solution.
  • Add the project file above to the solution (Add Existing Project).
  • Replace the global.json file contents with the following (adjust the location of the sources to point to the repos cloned on the first step):
{
"projects": [
"src",
"C:/aspnet-source/hosting/src",
"C:/aspnet-source/mvc/src",
"C:/aspnet-source/http-abstractions/src"
],
"sdk": {
"version":"1.0.0-beta6-11944"
}
}

VS should start restoring dependencies and adding the projects found on the ASP.NET sources to the solution. If not, try closing and reopening the solution.

  • Add a breakpoint on Microsoft.AspNet.Hosting –> Program –> Main.
  • Launch the debugger using the “web” command and wait for it to break on the breakpoint above.

That’s it! You can now debug into ASP.NET code. I’ll go into this code on the following posts.

Advertisements

One thought on “An Inside Look at ASP.NET 5 Execution – Setup for Debugging

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s