.net core, C# tip

Upgrading from .NET Core 1.0 to 1.1 with Visual Studio 2015

I’ve been experimenting with .NET Core – and creating my new projects with Visual Studio 2015. There are a few gotchas – I think Microsoft understand that the numbering conventions need some work, and I’d expect these to be sorted out soon. I’ve found this a bit confusing, so I wanted to post my findings and workarounds in case anyone else was struggling too.

As is the case with a few of my posts – which cover preview technologies – I hope this information becomes obsolete soon, as new and more stable packages are released.

Some useful links are below:

  • The .NET Core Download page is here.
  • I’ve installed the .NET Core 1.1 SDK (64 bit) from here.
    • The file is called: dotnet-dev-win-x64.1.0.0-preview2-1-003177.exe

screenshot-1479660931

  • I’ve also installed the tools (Preview 2) for .NET Core 1.1 for Visual Studio 2015 from here.
    • The file is called: DotNetCore.1.0.1-VS2015Tools.Preview2.0.3.exe so unfortunately you can see it’s still marked as version 1.0.1.

screenshot-1479660318When I had installed the new .NET Core SDK (v 1.1), there was a new SDK folder on my hard disk at C:\Program Files\dotnet\sdk, as shown below. You can see I’ve also installed a couple of other previous versions of .NET Core which can happily exist side by side.

screenshot-1479661066It’s worth noting that the .NET Core 1.1 SDK has a folder that doesn’t actually contain the version number “1.1” – it’s still marked as “1.0.0”, but it at least has the sub-version of 3177 present at the end of the folder name.

Creating a new project targeting .NET Core 1.1 with Visual Studio 2015

I opened Visual Studio 2015 and created a new Web API project targeting .NET Core. VS2015 doesn’t specify the target version at the time of project creation.

screenshot-1479661596

Immediately after creating the project, VS2015 alerted me that it was restoring packages, and it completed this successfully. However, if I open the global.json file for this project, we can see it does not target .NET Core v1.1.

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-preview2-003131"
  }
}

It’s a bit confusing to see what version is actually being targeted as the version numbers are in such a state of flux – however, for version 1.1, I would expect the SDK version to be specified as : 1.0.0-preview2-1-003177. I literally just copied this text from the folder name of the SDK I want to target which is stored under “C:\Program Files\dotnet\sdk”.

The code below shows the project.json text created by Visual Studio for the project.
The text created in the default version of project.json is pasted below – this all targets .NET Core v1.0:

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "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"
  },
 
  "tools": {
    "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": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

We can prove this project configuration targets .NET Core 1.0 by building the project as it is using a PowerShell prompt – I’ve pasted the output from this build operation below:

PM> dotnet build
Project MyWebAPI (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
Compiling MyWebAPI for .NETCoreApp,Version=v1.0

Compilation succeeded.
    0 Warning(s)
    0 Error(s)

Time elapsed 00:00:02.8137094

You can see in the console output above that Version=v1.0 is presently targeted.

Upgrading to .NET Core 1.1

To upgrade, first I change the version specified in global.json to use the version “1.0.0-preview2-1-003177”.

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-preview2-1-003177"
  }
}

Next, we need to update the project.json file in the Web project itself. I needed to change this – in two places:

  • The version of Microsoft.NETCore.App needs to be updated to 1.1.0 (from 1.0.1)
  • The framework “netcoreapp1.0” needs to be updated to “netcoreapp1.1

I’ve pasted the corrected project.json below:

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.1.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "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"
  },
 
  "tools": {
    "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"
    ]
  },
 
  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

We’re not done yet – whereas if we build the projects we’ll see that version 1.1 is being targeted, but we’re not going to see many changes from 1.1 until we update the APIs available to us. To do this, we need to update NuGet packages, but fortunately this is easy.

  • I open a PowerShell prompt (by going to Tools -> NuGet Package Manager -> Package Manager Console) – first I check my present working directory is at the root of my solution by typing “pwd”.
  • Next I type “Update-Package” to get the latest NuGet packages for the v1.1 configuration.
  • Next, I type “dotnet restore” (I think that this step is technically not necessary, but I like to do it to be sure I have updated the entire solution).
  • Finally, I change directory into my project by typing “cd .\src\MyWebAPI” (my project is called “MyWebAPI”, yours will be different), and then I type “dotnet build“to compile the project. The text below is written to the console.
PM> dotnet build
Project MyWebAPI (.NETCoreApp,Version=v1.1) will be compiled because inputs were modified
Compiling MyWebAPI for .NETCoreApp,Version=v1.1

Compilation succeeded.
    0 Warning(s)
    0 Error(s)

Time elapsed 00:00:01.6162872

As you can see, the version v1.1 is now targeted. I hope this helps anyone who’s trying to upgrade to the new SDK – I’ve pasted a link to some more official Microsoft information below.


About me: I regularly post about .NET – if you’re interested, please follow me on Twitter, or have a look at my previous posts here. Thanks!

Announcing the Fastest ASP.NET Yet, ASP.NET Core 1.1 RTM

One thought on “Upgrading from .NET Core 1.0 to 1.1 with Visual Studio 2015

Comments are closed.