Saturday, January 28, 2017

How to upgrade your ASP.NET Core application from 1.0 to 1.1

TL;DR;

In this blog, We are going to learn how we can upgrade your ASP.NET Core application from 1.0 to 1.1.  Now Microsoft has release 1.1 before few months, So in this blog, we will see how you can upgrade your ASP.NET 1.0 application to ASP.NET 1.1 core application.

Where to download 1.1 SDK and Tooling for Visual Studio 2015:

You can download 1.1 SDK and Tools from the following link.

https://www.microsoft.com/net/download/core?tduid=(42c8fb30096a508e70a0e7f0d6bdaf55)(256380)(2459594)(TnL5HPStwNw-1.6L2HANlqPr5.uZiHJ1MQ)()#/current

where-to-download-tooling-and-sdk-for-core1.1

Here different tooling is also available for the Visual Studio 2015 and Visual Studio 2017. For this blog post, We are going to use Visual Studio 2015.

How to upgrade to ASP.NET core 1.0 to ASP.NET core 1.1:

So let’s get started. I’m going to create a new ASP.NET Core 1.1 application and then we will move it to ASP.NET 1.1. So let’s create an ASP.NET core 1.0 application and then let’s upgrade it to 1.1. I have created a new application like following.

creating-new-aspnet-core-app-to-upgrade-to-11

Once you click ok it will have a dialog selecting application type and I’m going to select web application.

web-application-aspnet-core-11

Once you click Ok, It will create an application like below and you can see that it’s an ASP.NET Core 1.0 application.

aspnet-core-1.0-app-in-solution-explorer

And here’s how it’s project.json looks like.
{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
  },

  "tools": {
    "BundlerMinifier.Core": "2.0.238",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

And here’s how the global.JSON looks like.
{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-preview2-003131"
  }
}
So the first thing we need to is to upgrade the global.json to latest version like below.
{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-preview2-1-003177"
  }
}


So here in project.json, you can see that all packages belong to 1.0. Now there is multiple ways we can do upgrade either we can manually upgrade all packages via manually upgrading it or we can do it with Visual Studio tooling. I’m going to use Visual Studio tooling as that is the easiest way to do it. You can do this via Right Click your application and Select “Manage Nuget Packages for this solution”. It will load the following dialog. You need to goto Update tab of that dialog.

upgrade-nuget-package-to-1.1

You need to select upgrade all packages and update your application. Once you did with that there is once place where you need to manually upgrade it in project.json. GoTo following part of project.json.
"frameworks": {
  "netcoreapp1.0": {
    "imports": [
      "dotnet5.6",
      "portable-net45+win8"
    ]
  }
},
Now upgrade netcoreapp1.0 to 1.1 like below.
"frameworks": {
  "netcoreapp1.1": {
    "imports": [
      "dotnet5.6",
      "portable-net45+win8"
    ]
  }
},
Now once you do that and build your application. You might get the error like following.

error-for-runtime-application-net-core

That is because of windows runtime is not there for 1.1. So you need to add following in project.json.
"runtimes": {
  "win10-x64": {}
},
Now once you add that in project.json. It will restore the runtime for your operating system and it will start building your application.
And here’s how my project.json looks like after upgrading all stuff.
{
  "dependencies": {
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "BundlerMinifier.Core": "2.2.306",
    "Microsoft.Extensions.Logging": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.Extensions.Logging.Debug": "1.1.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
    "Microsoft.NETCore.App": "1.1.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0",
    "Microsoft.AspNetCore.Diagnostics": "1.1.0",
    "Microsoft.AspNetCore.Mvc": "1.1.1",
    "Microsoft.AspNetCore.Routing": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.AspNetCore.StaticFiles": "1.1.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0"
  },

  "tools": {
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.1": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },


  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },

  "runtimes": {
    "win10-x64": {}
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

And in solution explorer, you can see that now it’s targeting to 1.1.

targeting-11-upgrade-to-11-solutionexplorer

That’s it. It’s pretty easy to upgrade your application to latest build. Hope you like it. Stay tuned for more!!
Share:

0 comments:

Post a Comment

Your feedback is very important to me. Please provide your feedback via putting comments.

Search This Blog
About Me
My Photo

Full Stack Developer,Blogger,Microsoft Mvp, Mentor, Life long learner, 12+ Years of Experience for JavaScript, web and Microsoft technologies. ASP.NET MVC,Web Forms,C#,AngularJs,Golang
Mvp profile
Subscribe to my blog

Enter your email address:

Follow us on facebook
Blog Archive
Total Pageviews