Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't build project from command line after upgrading to .NET Core 2.1 #9632

Closed
ArcanoxDragon opened this issue Jul 29, 2018 · 4 comments
Closed
Milestone

Comments

@ArcanoxDragon
Copy link

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:

WEB_PROJECT
    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]
@ArcanoxDragon
Copy link
Author

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

@nguerrera
Copy link
Contributor

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

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

@nguerrera
Copy link
Contributor

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

@nguerrera
Copy link
Contributor

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 dotnet/msbuild#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 #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants