我在我从未遇到过问题的解决方案中构建一些 C# 项目时遇到了麻烦。构建失败并显示缺少元数据文件的错误。诊断级别的错误描述和 msbuild 日志输出显示了一些令人惊讶的进展。我遇到这个问题的项目之一叫做 WpfControlLibrary
.它引用了解决方案中的以下项目:
Helpers
HunAlmex.Kioszk.Common
HunAlmex.Kioszk.Communication.ImportedServiceContracts
HunAlmex.Kioszk.Data
解决方案文件夹是
"D:\Entegro\TFS\Volánbusz TVM\Bugfixes 2018-06"
.构建失败错误如下:
Error CS0006 Metadata file 'D:\Entegro\TFS\Volánbusz TVM\Bugfixes 2018-06\HunAlmex.Kioszk.Data\bin\Debug\WpfControlLibrary.dll' could not be found (in project WpfControlLibrary; file CSC)
所以当我构建
WpfControlLibrary
时项目,CSC
正在寻找一个以 bin\debug
中的项目命名的 dll。项目之一的文件夹 WpfControlLibrary
项目正在引用。构建日志显示上述所有四个项目引用都是这种情况。构建正在寻找一个名为
WpfControlLibrary.dll
的 dll在他们的 bin\debug
似乎正确构建这些项目后的文件夹(这些项目是使用正确命名的 dll 和 pdb 文件构建的)。构建错误可能只包含一个丢失的 dll,因为它在第一个错误时失败。但是,如果我构建了整个解决方案,并观看了
bin\debug
Helpers
的文件夹项目,我看到项目构建正确,然后在构建过程中,Helpers.dll
文件消失,出现一个名为WpfControlLibrary.dll
的文件(和 pdb)。构建最终失败,因为它没有找到 Helpers.dll
.项目
WpfControlLibrary
项目引用没有引用 WpfControlLibrary
.以上结果由
VS Enterprise 2017 version 15.8.2
产生与 msbuild version 15.8.168.64424
.我最近更新了 VS,在为其他人工作了一段时间后又回到了这个解决方案,所以我不知道更新是否破坏了它。我尝试使用
VS Community 2017 version 15.2
在同一台计算机上构建有问题的项目与 msbuild version 15.1.1012.6693
,这可以很好地构建它们。该项目还可以在具有各种其他版本的 VS 和 msbuild 的其他计算机上正常构建。
我对 msbuild 了解不多,但我比较了 Enterprise 和 Community 构建日志,在以下几行之后,前者的 dll 名称似乎变酸了:
Task Parameter:
1> Properties=
1> Configuration=Debug
1> Platform=AnyCPU (TaskId:12)
1> Global Properties: (TaskId:12)
1> Configuration=Debug (TaskId:12)
1> Platform=AnyCPU (TaskId:12)
1> Removing Properties for project "..\Helpers\Helpers.csproj": (TaskId:12)
1> TargetFramework (TaskId:12)
1> Removing Properties for project "..\HunAlmex.Kioszk.Common\HunAlmex.Kioszk.Common.csproj": (TaskId:12)
1> TargetFramework (TaskId:12)
1> Removing Properties for project "..\HunAlmex.Kioszk.Communication.ImportedServiceContracts\HunAlmex.Kioszk.Communication.ImportedServiceContracts.csproj": (TaskId:12)
1> TargetFramework (TaskId:12)
1> Removing Properties for project "..\HunAlmex.Kioszk.Data\HunAlmex.Kioszk.Data.csproj": (TaskId:12)
1> TargetFramework (TaskId:12)
这些在社区构建日志中缺失,但可能还有很多其他差异。
我不确定这是 VS 的错。可能是构建过程采用了构建目标的全局 msbuild 文件已损坏。我尝试修复 VS,但没有任何区别。
我正在链接下面的构建日志。
我有一种预感,我只能通过删除并重新安装或修复已安装的 .NET Framework 版本来解决此问题。我可以简单地从
Control Panel / Programs and Features / <.NET Framework version> / Repair
做到这一点吗?在上下文菜单中?在 https://drive.google.com/file/d/1NqLrzkmQhYSoYQxoja76NQp484gWNTHL/view?usp=sharing 下载压缩的诊断级构建日志
更新
构建日志引用了
Microsoft.Common.CurrentVersion.targets
每个项目的文件。例如:1>Target "GetTargetPathWithTargetPlatformMoniker: (TargetId:19)" in file "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets" from project "D:\Entegro\TFS\Volánbusz TVM\Bugfixes 2018-06\Helpers\Helpers.csproj" (target "GetTargetPath" depends on it):
1>Added Item(s):
1> TargetPathWithTargetPlatformMoniker=
1> D:\Entegro\TFS\Volánbusz TVM\Bugfixes 2018-06\Helpers\bin\Debug\Helpers.dll
1> CopyUpToDateMarker=D:\Entegro\TFS\Volánbusz TVM\Bugfixes 2018-06\Helpers\obj\Debug\Helpers.csproj.CopyComplete
1> TargetFrameworkIdentifier=.NETFramework
1> TargetFrameworkVersion=4.0
1> TargetPlatformIdentifier=Windows
1> TargetPlatformMoniker=Windows,Version=7.0
1>Done building target "GetTargetPathWithTargetPlatformMoniker" in project "Helpers.csproj".: (TargetId:19)
如果我用 VS 社区构建日志引用的文件替换该文件并构建项目,它仍然会给出相同的错误。但是,如果我清理该项目,然后进行构建,它会毫无错误地构建它。对于 VS 和 msbuild 版本,请参见上文。我链接下面的两个文件。文件名显示了它们的版本。
企业:https://drive.google.com/open?id=1MPnAVQxMtjTcuy39pzmLJolIroBaDgMt
社区:https://drive.google.com/open?id=19Jn8UkRaJ5oAFXreXI4IpRKmGrnjtGQ8
我将尝试使用显示此行为的项目编译一个小型解决方案。
更新 2
我创建了一个仅包含 WpfControlLibrary 项目及其依赖项的解决方案。您可以在以下链接下载:
使用下面更新 4 下的更新链接
我只是将项目文件夹复制到一个新文件夹中,然后将它们添加到新解决方案中。我不得不稍微修改 csproj 文件,因为每个文件中的以下部分导致标准 .NET 4 项目引用(系统等)在解决方案资源管理器中显示为未找到:
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
我的解决方案是注释掉这部分,这导致项目正确打开。我还删除并重新添加了引用的 Nuget 包,以防万一。
还原 NuGet 包后,构建解决方案会导致以下错误:
Metadata file 'D:\Entegro\VB TVM\Playground\2018-09-04 VS Build Error\BuildFailure\HunAlmex.Kioszk.Data\bin\Debug\WpfControlLibrary.dll could not be found (Project: WpfControlLibrary; File: CSC)
因此,现在重现了上述错误。
通过从
WpfControlLibrary
中排除所有 xaml 文件,我设法消除了构建错误。项目。我在将它们一一重新添加后构建了解决方案,但无法得出结论是哪个导致了错误,因为它有所不同。有一次,通过删除对 HunAlmex.Kioszk.Communication.ImportedServiceContracts 项目的引用,构建错误消失了。我不认为更换
Microsoft.Common.CurrentVersion.targets
file 是一个不错的解决方案,所以我希望有人能想出一个更好的解决方案。提前致谢。更新 3
VS 15.8.3 刚出来。更新到它后,构建示例解决方案的过程略有变化。构建错误如下:
The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://www.postsharp.net/links/nuget-restore. WpfControlLibrary D:\Entegro\VB TVM\Playground\2018-09-04 VS Build Error\BuildFailure\WpfControlLibrary\WpfControlLibrary.csproj
错误仍然存在于后续构建中并且永远不会消失,除非我只构建了
WpfControlLibrary
项目。然后我们回到最初的构建错误。更新到 VS 15.8.4 也没有修复它。
因为这些项目已经看到了自 VS 2010 以来许多版本的 VS 来来去去,所以我有一种预感,csproj 文件可能处于不一致的状态。我将尝试创建新项目并将代码文件添加到其中。
更新 4
我刚刚使用新项目创建了一个新解决方案,并向其中添加了代码文件。不幸的是,构建以相同的错误结束。您可以在此处下载解决方案:
https://drive.google.com/open?id=1oMtwc8aD0kxE6jmtoF05Z5ROZ7diQzUQ
更新 5
这个问题可能与
Microsoft.Common.CurrentVersion.targets
无关文件,因为我将它与另一个相同版本的 VS Enterprise 安装进行了比较,并且它们匹配。我会尝试卸载并重新安装VS。
更新 6
解决方案中的一些项目使用了
PostSharp
NuGet 包版本 4.1.23。将它们更新到最新版本 6.0.27 解决了该问题。解决方案再次构建良好。
最佳答案
更新 - 事实证明,Visual Studio 更新中有重大更改,大约 15.8.3,这导致使用 PostSharp 早期版本的问题 - 我认为 Drew 和我自己在 4.x 上。将 PostSharp 更新到最新版本 6.0.27,在努力处理我的方面中引入的一些重大更改后解决了该问题。
原帖如下。
本周有一个我几个月没碰过的项目也有同样的问题。我在星期二克隆了 repo,NCrunch 构建得很好。昨天,我将 VS2017 更新到 15.8.4 并且 NCrunch 仍在构建它。但是……现在,当我按 F5 时,32 个项目中有 4 个给了我 CS0006。查看详细的构建日志,我看到了:
1>Target "ResolveAssemblyReferences" in file "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets" from project "D:\Repos\g\Game.Client.Wpf\Game.Client.Wpf_ftfxk2qp_wpftmp.csproj" (target "PostSharp30InspectReferences" depends on it):
1>Using "ResolveAssemblyReference" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>Task "ResolveAssemblyReference"
1> TargetFrameworkMoniker:
1> .NETFramework,Version=v4.7.2
1> TargetFrameworkMonikerDisplayName:
1> .NET Framework 4.7.2
1> TargetedRuntimeVersion:
1> v4.0.30319
1> Assemblies:
1> System.Core
1> AssemblyFiles:
1> D:\Repos\g\EntityComponentSystem\bin\Debug\Lafs2.dll
1> D:\Repos\g\Framework.Unity\bin\Debug\Lafs2.dll
1> D:\Repos\g\Framework\bin\Debug\Lafs2.dll
1> D:\Repos\g\Game.Controls.Wpf\bin\Debug\Lafs2.dll
1> D:\Repos\g\Game.Messages\bin\Debug\Lafs2.dll
1> D:\Repos\g\Logging.Metrics\bin\Debug\Lafs2.dll
1> D:\Repos\g\Logging\bin\Debug\Lafs2.dll
1> D:\Repos\g\NetCode\bin\Debug\Lafs2.dll
1> D:\Repos\g\Universe.Client\bin\Debug\Lafs2.dll
1> D:\Repos\g\Universe.Physics\bin\Debug\Lafs2.dll
1> D:\Repos\g\Universe\bin\Debug\Lafs2.dll
1> C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\mscorlib.dll
当前构建项目的程序集名称已替换了 AssemblyFiles 中所有项目的文件名。 CS0006 说它在应该查找 D:\Repos\g\Universe\bin\Debug\Universe.dll 时找不到 D:\Repos\g\Universe\bin\Debug\Lafs2.dll。
关于c# - msbuild 使用了错误的程序集名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52187407/