Skip to content

Unable to build a netstandard2.0 project from a net8.0 unit test #336

Description

I have a unit test which builds several projects targeting net46 and netstandard2.0. net46 ones build successfully, but netstandard2.0 ones fail with the following error:

C:\Program Files\dotnet\sdk\8.0.315\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(284,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly.
System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.DependencyModel, Version=8.0.0.2, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (0x80131621)
File name: 'Microsoft.Extensions.DependencyModel, Version=8.0.0.2, Culture=neutral, PublicKeyToken=adb9793829ddae60'
 ---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.DependencyModel, Version=8.0.0.2, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at Microsoft.NET.Build.Tasks.GenerateDepsFile.WriteDepsFile(String depsFilePath)
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\Users\DarkDaskin\Documents\Development\UnityModStudio\UnityModStudio.Build.Tests\bin\Debug\net8.0\Projects\Correct\MultiVersionMultiTarget\MultiVersionMultiTarget.csproj]

The same projects can be built with dotnet build without problems.

I also tried to switch my unit tests to net9.0, but the same error persists (with different assembly version).

I use MSBuildLocator.RegisterDefaults(); to locate an MSBuild instance.

Installing the Microsoft.Extensions.DependencyModel package into the unit test project allows to build everything successfully, but I guess that MSBuildLocator should have loaded this assembly from the SDK directory automatically.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions