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

Assembly with same name (Nerdbank.GitVersioning.Tasks) is already loaded when using <TargetFrameworks>net45;netstandard2.0</TargetFrameworks> #374

Closed
pcshrosbree opened this issue Aug 15, 2019 · 3 comments

Comments

@pcshrosbree
Copy link

Create a library project with:

<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>

that references Nerdbank.GitVersioning with 2.3.181 <= Version <= 3.0.25 (may occur with other versions, but I only tested these versions)

Running dotnet build <name>.csproj -t:Build -p:Configuration=Release fails with:

Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 174.91 ms for <name>.csproj.
<user>\.nuget\packages\nerdbank.gitversioning\3.0.25\build\Nerdbank.GitVersioning.targets(63,5): error MSB4062: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task could not be loaded from the assembly <user>\.nuget\packages\nerdbank.gitversioning\3.0.25\build\MSBuildCore/Nerdbank.GitVersioning.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. [<name>.csproj]
  Microsoft.Torch.Common -> C:\src\microsoft\torch-int\torch.temp\Light45\src\lib\Microsoft.Torch.Common\bin\Release\net45\Microsoft.Torch.Common.dll

Build FAILED.

The net45 target is built, but not the netstandard2.0.

Build also fails with a framework command line parameter such as:

dotnet build <name>.csproj -t:Build -p:Configuration=Release --framework netstandard2.0
dotnet build <name>.csproj -t:Build -p:Configuration=Release --framework net45

Build is successful if TargetFrameworks has only one of the TFMs:

<TargetFrameworks>net45</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>

dotnet msbuild <name>.csproj -p:Configuration=Release also fails as follows:

Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

<user>\.nuget\packages\nerdbank.gitversioning\3.0.25\build\Nerdbank.GitVersioning.targets(63,5): error MSB4062: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task could not be loaded from the assembly <user>\.nuget\packages\nerdbank.gitversioning\3.0.25\build\MSBuildCore/Nerdbank.GitVersioning.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. [<name>.csproj]
  <name> -> <name>\bin\Release\net45\<name>.dll
@AArnott
Copy link
Collaborator

AArnott commented Aug 15, 2019

This is a failing in MSBuild Core I guess, which isn't properly handling multi-load or unload of msbuild task assemblies.

From my experience with this, I'm pretty sure it actually has nothing to do with the fact that you're targeting multiple frameworks in your own project. Rather, it's because you've previously built some project that consumes a different version of NB.GV. That build was in a process that stuck around and served your subsequent build request. You can clear out these problematic processes by running dotnet build-server shutdown then building again. This will guarantee you have fresh msbuild processes and you should get just one version of NB.GV loaded and it will work.

The other possibility is that you have a single solution/repo which consume multiple versions of NB.GV. That makes it double-hard for msbuild to get the assembly loading right, so you should definitely make sure each repo references exactly one version of NB.GV. Then your dotnet build-server shutdown command gets you to a clean slate and your repo can build with its one version.

@AArnott
Copy link
Collaborator

AArnott commented Aug 15, 2019

See #48 and linked issues for a history of this.

@AArnott AArnott closed this as completed Aug 15, 2019
@pcshrosbree
Copy link
Author

Thank you, @AArnott. dotnet build-server shutdown worked locally, so that's great. What is weird is that I picked up this problem when I pushed this to an AzDO PR. VS builds at the time were fine. However, the latest push worked fine.

Thank you again for unblocking me.

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

2 participants