Skip to content

[Bug] .NET 8.0: MSB4062 The "WriteVersionInfoToBuildLog" task could not be loaded #3787

@mdavis

Description

@mdavis

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.

Steps to Reproduce

Here's a sample solution: https://bama365-my.sharepoint.com/:f:/g/personal/davis011_ua_edu/Eg1y5HDjMclBoyuGvo3InIQB7Rtwq6NIX2y-tNGcYLQ3UQ?e=UywT5g

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions