You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] .NET 8.0: MSB4062 The "WriteVersionInfoToBuildLog" task could not be loaded #3787
As seen in #3704 and #3450, trying to use GitVersion with .NET 8.0 project causes the build to fail with error MSB4062.
Expected Behavior
The build should complete successfully.
Actual Behavior
Adding GitVersion to .NET 8 projects causes a build failure with a message like the following:
C:\Users\...\.nuget\packages\gitversion.msbuild\6.0.0-beta.233\tools\GitVersion.MsBuild.targets(22,9): error MSB4062: The "WriteVersionInfoToBuildLog" task could not be loaded from the assembly C:\Users\...\.nuget\packages\gitversion.msbuild\6.0.0-beta.233\tools\net8.0/GitVersion.MsBuild.dll. Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. 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.
I have tried with the following versions, all of which fail:
5.12.0 (the latest release on nuget.org)
6.0.0-beta.3 (the latest prerelease build on nuget.org)
6.0.0-beta.233 (the latest build on GitHub Packages)
For the first two, the only difference I see in the error message is the part of the path indicating a framework version.
5.12.0: uses net48
6.0.0-beta.3: uses net6.0
For 6.0.0-beta.233, it initially seems to have nothing in that location (...\tools\/GitVersion.MSBuild.dll) and the error changes to indicate that it couldn't find the file. If I add a Directory.Build.props file at the solution root and set the TargetFramework property in it to net8.0, then it will get the path to the DLL correct, but it still gives the error about being unable to load System.Runtime.
If I drop the target framework of the individual apps back down to net6.0 (or things like net6.0-windows) then 5.12.0 will work, but neither of the 6.0.0 beta builds work for me.
I included both a class library project and a WPF project just to make sure that something was included that has a Windows specific target framework (i.e., net8.0-windows).
Note that I have put the PackageReference for GitVersion into the Directory.Build.props file, as this is how I usually prefer to use it so I don't have to manually add it to each project in the solution.
@arturcic Building from the command line using dotnet build or dotnet msbuild appears to work. However, building from the command line using msbuild or building from Visual Studio 2022 17.8.0 both give the original error.
Here's the output of msbuild -version:
MSBuild version 17.8.3+195e7f5a3 for .NET Framework
17.8.3.51904
dotnet msbuild -version:
MSBuild version 17.8.3+195e7f5a3 for .NET
17.8.3.51904
dotnet --version:
8.0.100
This suggests to me that VS is using the .NET Framework version of MSBuild, so if you can figure out how to get it working with that, then hopefully it'll fix the problem with VS as well.
Activity
christophwille commentedon Nov 17, 2023
As the author of #3704 this reminded me - could we please get a new 6.0 beta build?
arturcic commentedon Nov 19, 2023
@mdavis I've tried the archive you provided in a windows sandbox where I installed only .net 8.0.100 sdk, and it built successfully.
Can you try it yourself?
mdavis commentedon Nov 20, 2023
@arturcic Building from the command line using
dotnet buildordotnet msbuildappears to work. However, building from the command line usingmsbuildor building from Visual Studio 2022 17.8.0 both give the original error.Here's the output of
msbuild -version:dotnet msbuild -version:dotnet --version:This suggests to me that VS is using the .NET Framework version of MSBuild, so if you can figure out how to get it working with that, then hopefully it'll fix the problem with VS as well.
Disable GitVersion task when running with MsBuild on .NET Framework (…
Merge pull request #3827 from arturcic/#3787