Sdk: Can't build project from command line after upgrading to .NET Core 2.1

Created on 29 Jul 2018  路  4Comments  路  Source: dotnet/sdk

I just installed the latest .NET Core 2.1 SDK (2.1.302) from the Microsoft website, updated my 4 project files to use netcoreapp2.1, and updated all NuGet packages from within Visual Studio 2017 (15.8.0 Preview 4). I can build and run the project fine using Visual Studio, but I can't use any dotnet CLI commands now. I have tried dotnet restore, dotnet build, and several dotnet ef commands, and they all result in a Build FAILED message with the following output:

Microsoft (R) Build Engine version 15.8.138-preview+ge0cd4f1c1f for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Program Files\dotnet\sdk\2.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(214,5): error MSB4062: The "CheckForImplicitPackageReferenceOverrides" task could not be loaded from the assembly C:\Program Files\dotnet\sdk\2.1.302\Sdks\Microsoft.NET.Sdk\targets\..\tools\netcoreapp2.0/Microsoft.NET.Build.Tasks.dll. Assembly with same name is already loaded Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:\Development\Projects\<LIBRARY_SOLUTION_NAME><LIBRARY_3_NAME>\<LIBRARY_3_NAME>.csproj]
C:\Program Files\dotnet\sdk\2.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(214,5): error MSB4062: The "CheckForImplicitPackageReferenceOverrides" task could not be loaded from the assembly C:\Program Files\dotnet\sdk\2.1.302\Sdks\Microsoft.NET.Sdk\targets\..\tools\netcoreapp2.0/Microsoft.NET.Build.Tasks.dll. Assembly with same name is already loaded Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:\Development\Projects\<LIBRARY_SOLUTION_NAME>\<LIBRARY_1_NAME>\<LIBRARY_1_NAME>.csproj]

Build FAILED.

C:\Program Files\dotnet\sdk\2.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(214,5): error MSB4062: The "CheckForImplicitPackageReferenceOverrides" task could not be loaded from the assembly C:\Program Files\dotnet\sdk\2.1.302\Sdks\Microsoft.NET.Sdk\targets\..\tools\netcoreapp2.0/Microsoft.NET.Build.Tasks.dll. Assembly with same name is already loaded Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:\Development\Projects\<LIBRARY_SOLUTION_NAME>\<LIBRARY_3_NAME>\<LIBRARY_3_NAME>.csproj]
C:\Program Files\dotnet\sdk\2.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(214,5): error MSB4062: The "CheckForImplicitPackageReferenceOverrides" task could not be loaded from the assembly C:\Program Files\dotnet\sdk\2.1.302\Sdks\Microsoft.NET.Sdk\targets\..\tools\netcoreapp2.0/Microsoft.NET.Build.Tasks.dll. Assembly with same name is already loaded Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:\Development\Projects\<LIBRARY_SOLUTION_NAME>\<LIBRARY_1_NAME>\<LIBRARY_1_NAME>.csproj]
    0 Warning(s)
    2 Error(s)

Time Elapsed 00:00:00.62

My solution has 4 projects. The main project is a Microsoft.NET.Sdk.Web project. The project reference tree looks like this:

    LIBRARY_1
    LIBRARY_2
        LIBRARY_1
    LIBRARY_3
        LIBRARY_1
        LIBRARY_2

I am calling dotnet build in the folder containing WEB_PROJECT. I have tried clearing out all bin and obj folders to no avail. I have updated my MSBuildSdksPath to point to C:\Program Files\dotnet\sdk\2.1.302\Sdks.

Environment data

dotnet --info output:

.NET Core SDK (reflecting any global.json):
 Version:   2.1.400-preview-009063
 Commit:    dd0179a67c

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.16299
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.400-preview-009063\

Host (useful for support):
  Version: 2.1.2
  Commit:  811c3ce6c0

.NET Core SDKs installed:
  1.0.0-preview2-003131 [C:\Program Files\dotnet\sdk]
  1.0.3 [C:\Program Files\dotnet\sdk]
  1.0.4 [C:\Program Files\dotnet\sdk]
  1.1.0 [C:\Program Files\dotnet\sdk]
  2.0.0-preview2-006497 [C:\Program Files\dotnet\sdk]
  2.0.3-servicing-007156 [C:\Program Files\dotnet\sdk]
  2.1.105 [C:\Program Files\dotnet\sdk]
  2.1.201 [C:\Program Files\dotnet\sdk]
  2.1.302 [C:\Program Files\dotnet\sdk]
  2.1.400-preview-009063 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 1.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

Most helpful comment

I think you can also hit this error when switching between certain .NET Core SDK versions that share the same msbuild version, even without setting MSBuildSdksPath.

And that would be due to https://github.com/Microsoft/msbuild/issues/3572. The fix for that would also have prevented this particular error in this case of MSBuildSdksPath set to another SDK location, but that's still not a supported configuration.

There is also https://github.com/dotnet/sdk/issues/2161 where you can hit related issues on desktop msbuild / VS.

If you encounter the error and haven't set MSBuildSdksPath, then you can try dotnet build-server shutdown.

I'm therefore closing this as being tracked by those two bugs in the cases where it's failing without MSBuildSdksPath being set.

All 4 comments

I have put together a Gist of my project setup with the same edited names as the build log:

https://gist.github.com/briman0094/67f33bbb60b6f9ddef894a68e7b5c97a

I have updated my MSBuildSdksPath to point to C:\Program Filesdotnet\sdk\2.1.302\Sdks

You shouldn't do this. Use global.json if you want to pin the SDK to 2.1.302.

You are ending up with the tools from SDK 2.1.400-preview-009063 but the Microsoft.NET.Sdk tasks and targets from SDK 2.1.302, and msbuild node reuse isn't letting the 2.1.400-* and 2.1.302 tasks load into the same process.

First thing to do, stop setting MSBuildSdksPath.

Then your options are:

  1. Just let dotnet build use latest (2.1.400-preview-009063 in your case)
  2. Uninstall 2.1.400-preview-009063 to prevent it from being used over 2.1.302
  3. Add a global.json file specifying 2.1.302 to prevent it from being used over 2.1.302

I think you can also hit this error when switching between certain .NET Core SDK versions that share the same msbuild version, even without setting MSBuildSdksPath.

And that would be due to https://github.com/Microsoft/msbuild/issues/3572. The fix for that would also have prevented this particular error in this case of MSBuildSdksPath set to another SDK location, but that's still not a supported configuration.

There is also https://github.com/dotnet/sdk/issues/2161 where you can hit related issues on desktop msbuild / VS.

If you encounter the error and haven't set MSBuildSdksPath, then you can try dotnet build-server shutdown.

I'm therefore closing this as being tracked by those two bugs in the cases where it's failing without MSBuildSdksPath being set.

Was this page helpful?
0 / 5 - 0 ratings