ProudMonkey

Upgrading Existing ASP.NET 5 previous versions to Beta8

Last month Microsoft announced the availability of ASP.NET 5 Beta8. This release greatly expands the supported surface area of .NET Core on OS X and Linux. You can now use networking, cryptography and globalization features cross-platform. Adding to that it also includes some awesome improvements to ASP.NET 5, DNX and the Web tools.

Now if you are working or exploring previous versions of ASP.NET 5 before or if you are following my previous articles about ASP.NET 5 and wanted to move your app to the latest beta version of ASP.NET 5 ( which is beta8 as of this writing) then for sure you will run into issues about references. This
post will walk you through of the few steps on how to upgrade your existing version to beta8 so don't panic ;)

Down to the road

(1) Install the Microsoft ASP.NET and Web Tools 2015 (Beta8) - Visual Studio 2015. You can download it here.

After the installation make sure to restart your machine to ensure updates will take effect.

(2) Enable ASP.NET 5 command-line tools. Open a Developer Command Prompt for VS2015 and run the following commands:

dnvm setup  
dnvm upgrade  

To check the currently installed DNX verions you can run the following command:

dnvm list  

Make sure that -beta8 is set as the default. If you have the need to switch between different versions of DNX, you can use the dnvm use command which has the following format:

dnvm use -r coreclr -arch <arch> <version>  

(3) Open your project and then open project.json file and then replace all instance of -beta* to -beta8 under dependencies section. For example:

  "dependencies": {
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-beta8",
    "Microsoft.AspNet.Mvc": "6.0.0-beta8",
    "Microsoft.Framework.DependencyInjection.Abstractions": "1.0.0-beta8",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8"
  },

(4) then under frameworks section replace this:

  "frameworks": {
        "aspnet50": { },
        "aspnetcore50": { }
    },

to this:

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

(5) and replace web command with Microsoft.AspNet.Server.Kestrel under command section. For example:

"commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
},

Now make sure to save your project.json file to restore the required packages.

(6) Under wwwroot folder add a web.config file with the following config:

<?xml version="1.0" encoding="utf-8"?>  
<configuration>  
  <system.webServer>
    <handlers>
      <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" forwardWindowsAuthToken="false" startupTimeLimit="3600" />
  </system.webServer>
</configuration>  

If you already have an existing web.config then make sure to modify the configuration same as above. The web.config file adds the HttpPlatformHandler to your application and configures the handler to forward requests to a DNX process. Visual Studio handles setting up the DNX_PATH environment variable to point to the appropriate DNX version for your application.

(7) Now right-click on your project solution and select properties. Under Application tab > Solution DNX SDK version, select 1.0.0-beta8 from the dropdown.

(8) and finally, make sure that your global.json file matches with the dnx version that you use (in this case -beta8). for example:

"sources": [ "src", "test" ],
    "sdk": {
        "version": "1.0.0-beta8",
        "runtime": "clr",
        "architecture": "x86"
}

(9) Modify your startup.cs to configure UseIISPlatformHandler.

public void Configure(IApplicationBuilder app){  
      app.UseIISPlatformHandler();
      app.UseMvc();  
}

(10) Rebuild and then run your application and you should be good :)