How to (really) migrate from .net core 2.0 to 2.1

According to Microsoft (https://docs.microsoft.com/en-us/dotnet/core/migration/20-21) it’s super simple to migrate from .NET Core 2.0 to 2.1. Just change netcoreapp2.0 to netcoreapp2.1, remove some CLI tools and you’re done!

When we tried this approach we ran into a NETSDK1061 issue. Below is a step by step on how we fixed it.

Note that there might be a few “Restart Visual Studio” steps missing from this guide. If things doesn’t work try restarting Visual Studio.

  1. Change netcoreapp2.0 to netcoreapp2.1 in your csproj files (remember to also change any test projects)
  2. Compile and get the error: NETSDK1061: The project was restored using Microsoft.NETCore.App version 2.1.3, but with current settings, version 2.1.3-servicing-26724-03 would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection.
  3. Open “Add or remove programs” from the Windows start menu
  4. Find “Microsoft .NET Core SDK 2.1.401 (x64)” and uninstall it
  5. Install the same version from https://www.microsoft.com/net/download/thank-you/dotnet-sdk-2.1.401-windows-x64-installer
  6. Compile and… still not working: NETSDK1061: The project was restored using Microsoft.NETCore.App version 2.1.3, but with current settings, version 2.1.0 would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection
  7. Add <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> to the csproj files of the projects in the error list.
    Example:
    1
    2
    3
    4
    5
    6
    <PropertyGroup>
    <Description>My core app</Description>
    <Authors>...</Authors>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
    </PropertyGroup>
  8. Compile and voila! Profit!

Sources

Reinstall .NET Core SDK issue and work around: https://github.com/dotnet/cli/issues/9897#issuecomment-417088742
TargetLatestRuntimePatch issue and work around: https://github.com/dotnet/cli/issues/9624