Skip to content

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

Closed

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.

Activity

  1. christophwille commented on Nov 17, 2023

    @christophwille

    As the author of #3704 this reminded me - could we please get a new 6.0 beta build?

  2. arturcic commented on Nov 19, 2023

    @arturcic
    Member

    @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?

    image

  3. mdavis commented on Nov 20, 2023

    @mdavis
    Author

    @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.

  4. self-assigned this
    on Dec 2, 2023
  5. added a commit that references this issue on Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions