Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#336 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
csharp

调研方向

从单元测试项目的 MSBuildLocator.RegisterDefaults() 调用入手,将其程序集解析与成功的 dotnet build 进行比较。在目标框架为 net8.0 或 net9.0 时,复现 netstandard2.0 项目的 GenerateDepsFile 失败,然后比较测试项目安装和未安装 Microsoft.Extensions.DependencyModel 时的行为。完成标准是:无需使用该包作为变通方案,即可从单元测试构建这些项目。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
C#
星标
262
派生
91
平均合并
11 天 22 小时
30 天内合并 PR
3

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/MSBuildLocator 的其他 Issue

查看 microsoft/MSBuildLocator 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。