首页 文章

MSBuild有时失败,缺少引用

提问于
浏览
1

我使用VS 2013在TFS 2013中创建了一个版本 . 我的解决方案在Visual Studio中正确构建,我可以从构建服务器上的drop文件夹中打开解决方案并进行编译 .

问题是触发的构建将随机失败,可能在大约60%的时间内失败,缺少参考错误 . 缺少的引用只是我自己的项目,这些项目是使用解决方案构建的,而不是包或Microsoft dll . 实际缺失的引用错误的数量也不同,这让我相信问题与文件访问句柄有关 . 构建失败,标准为“MSBuild错误1” . 这是一个示例错误:

Helpers\SiteHelpers.cs (11): The type or namespace name 'ShoppingCart' does not exist in the namespace 'xxxxx.xxxxxxxxx.xxxxxxx' (are you missing an assembly reference?)

正如我所说,该项目在Visual Studio中构建得很好,但无论如何我检查了对解决方案的依赖性,一切看起来都是正确的 .

值得注意的是我正在使用TFS的Git实现,因此我的构建过程文件目前是GitTemplate.12.xaml . 此文件适用于我正在处理的其他几个类似的解决方案 .

编辑:我打开了更详细的构建日志,这是在这个实例中碰巧失败的部分:

53>GenerateTargetFrameworkMonikerAttribute:
       Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
       CoreCompile:
         C:\Program Files (x86)\MSBuild\12.0\bin\amd64\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:AnyCPU /errorreport:prompt /define:TRACE /highentropyva- /reference:"C:\Builds\5\xxxxGit\xxxx xxxx\bin\BusinessObject.dll" /reference:"C:\Builds\5\xxxxGit\xxxx xxxx\bin\Configuration.dll" /reference:"C:\Builds\5\xxxxGit\xxxx xxxx\bin\DataProvider.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.Linq.dll" /reference:"C:\Builds\5\xxxxGit\xxxx xxxx\bin\Utilities.dll" /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\ScheduledTransmissionProcessor.exe /target:exe /utf8output Program.cs Properties\AssemblyInfo.cs "C:\Users\xxxxxuser\AppData\Local\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.cs"
    53>Program.cs(6,11): error CS0234: The type or namespace name 'BusinessLogic' does not exist in the namespace 'xxx' (are you missing an assembly reference?) [C:\Builds\5\xxxxGit\xxxx xxxx\src\Application\Console\ScheduledTransmissionProcessor\ScheduledTransmissionProcessor.csproj]

构建成功时,这是相同的部分:

52>GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
       CoreCompile:
         C:\Program Files (x86)\MSBuild\12.0\bin\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:AnyCPU /errorreport:prompt /define:TRACE /highentropyva- /reference:"C:\Builds\5\XXXXGit\XXXX XXXX\bin\BusinessLogic.dll" /reference:"C:\Builds\5\XXXXGit\xxxx xxxx\bin\BusinessObject.dll" /reference:"C:\Builds\5\XXXXGit\xxxx xxxx\bin\Configuration.dll" /reference:"C:\Builds\5\XXXXGit\xxxx xxxx\bin\DataProvider.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.Linq.dll" /reference:"C:\Builds\5\XXXXGit\xxxx xxxx\bin\Utilities.dll" /reference:"C:\Builds\5\XXXXGit\xxxx xxxx\bin\UtilityServices.dll" /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\ScheduledTransmissionProcessor.exe /target:exe /utf8output Program.cs Properties\AssemblyInfo.cs "C:\Users\xxxxxuser\AppData\Local\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.cs"
    53>CoreResGen:

似乎无法找到命名空间,因为该引用未包含在csc.exe的命令行参数中 .

什么会导致构建命令随机格式错误?它可能是构建机器上的资源吗?构建过程模板中有什么东西?

编辑2:以下是项目的.csproj文件中的项目引用示例,该文件导致我发布的错误日志中的构建失败:

<ProjectReference Include="..\..\..\BusinessLogic\BusinessLogic.csproj">
      <Project>{0C3A2268-388A-4C88-8D4C-982FB00E573D}</Project>
      <Name>BusinessLogic</Name>
</ProjectReference>

这个路径在我的机器和构建机器上是相同的,因为两个版本都是从同一个Git存储库克隆的 .

1 回答

  • 2

    我的解决方案中有几个项目正在使用不同的目标框架构建,每个项目都引用了相同的库(Newtonsoft.Json) . 对于依赖项,基本设置是这样的:

    项目A(目标框架.net 4.5)引用了项目B.

    项目A引用了项目C(目标框架.net 4.5) .

    项目B(目标框架.net 4.0)引用了项目C(目标框架.net 4.0) .

    我收到了警告,但Visual Studio构建了解决方案 . MSBuild将随机失败,仅在失败时显示警告 . 我不知道为什么随机元素存在,但解决方法是确保我的解决方案中的每个库都使用相同的目标框架进行引用 . 这包括更新packages.config和.csproj文件以指向相同的位置 .

相关问题