C# msbuild使用了错误的程序集名称

C# msbuild使用了错误的程序集名称,c#,.net,msbuild,visual-studio-2017,postsharp,C#,.net,Msbuild,Visual Studio 2017,Postsharp,我在构建一些C#项目时遇到了一些问题,我从来没有遇到过问题。生成失败,错误为缺少元数据文件。错误描述和诊断级别的msbuild日志输出显示了一些令人惊讶的发展。我遇到这个问题的一个项目叫做WpfControlLibrary。它引用了解决方案中的以下项目: Helpers HunAlmex.Kioszk.Common HunAlmex.Kioszk.Communication.ImportedServiceContracts HunAlmex.Kioszk.Data 解决方案文件夹是“D:\En

我在构建一些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)
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
项目时,
CSC
正在
WpfControlLibrary
项目引用的其中一个项目的
bin\debug
文件夹中查找以该项目命名的dll

构建日志显示,上述所有四个项目引用都是如此。在看似正确地构建这些项目之后,构建正在其
bin\debug
文件夹中查找名为
WpfControlLibrary.dll的dll(这些项目是使用正确命名的dll和pdb文件构建的)。生成错误可能只包含一个缺少的dll,因为它在第一个错误时失败

但是,如果我构建整个解决方案,并查看
Helpers
项目的
bin\debug
文件夹,我会看到该项目构建正确,然后在构建过程中,
Helpers.dll
文件消失,出现一个名为
WpfControlLibrary.dll
(和pdb)的文件。生成最终失败,因为它找不到
Helpers.dll

WpfControlLibrary
项目引用中的项目没有对
WpfControlLibrary
的引用

上述结果由
VS Enterprise 2017版本15.8.2
msbuild版本15.8.168.64424
生成。我最近更新了VS,并在处理其他解决方案一段时间后返回此解决方案,因此我无法判断更新是否破坏了它

我尝试在同一台计算机上使用
VS Community 2017 version 15.2
msbuild version 15.1.1012.6693
构建有问题的项目,这可以很好地构建它们

该项目还可以在具有各种其他版本的VS和msbuild的其他计算机上很好地构建

我对msbuild了解不多,但我比较了企业版和社区版的构建日志,在以下几行之后,前者的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版本,我才能解决这个问题。我可以通过上下文菜单中的
控制面板/程序和功能//修复
简单地执行此操作吗

下载压缩的诊断级别生成日志,网址为

更新

生成日志引用每个项目的
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版本,请参见上文。我链接下面的两个文件。文件名显示了它们的版本

企业:

社区:

我将尝试用显示这种行为的项目编译一个小型解决方案

更新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>
因此,现在重现上述错误

通过从
WpfControlLibrary
项目中排除所有xaml文件,我成功地消除了构建错误。在一个接一个地重新添加它们之后,我构建了解决方案,但无法得出导致错误的原因的结论,因为它不同。有一次,通过删除对HunAlmex.Kioszk.Communication.ImportedServiceContracts项目的引用,构建错误消失了

我不认为替换
Microsoft.Common.CurrentVersion.targets文件是一个不错的解决方案,所以我希望有人能想出一个更好的解决方案。提前谢谢

更新3

VS15.8.3刚刚发布。更新后,构建示例解决方案的过程略有变化。生成错误如下所示:

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)
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
项目。然后我们回到最初的构建错误

更新到VS15.8.4也没有修复它

由于这些项目自VS 2010以来已经出现了许多版本的VS,我有一种预感csproj文件可能处于不一致的状态。我将尝试创建新项目并将代码文件添加到其中

更新4

我刚刚用新项目创建了一个新的解决方案,并向其中添加了代码文件。不幸的是,构建完成时出现了相同的错误。您可以在此处下载解决方案:

更新5

这个问题可能与
Microsoft.Common.CurrentVersion.targets
文件无关,因为我将它与同一版本的另一个VS Enterprise安装进行了比较