MSBuild无法找到参考

我目前正在试图弄清楚为什么MSBuild无法编译我们的unit testingdll之一。 问题只出现在这个DLL而不是其他unit testing项目中。

这是我在构建失败时从TeamCity收到的输出:

[10:38:55]: NAnt output: [10:38:55]: [exec] [10:38:55]: [exec] [10:38:55]: [exec] "C:\Robinson\trunk\Projects\Robinson\Robinson.sln" (default target) (1) -> [10:38:55]: [exec] "C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj" (default target) (19) -> [10:38:55]: [exec] (CoreCompile target) -> [10:38:55]: [exec] Modules\SecurityModuleTests.cs(10,30): error CS0234: The type or namespace name 'Modules' does not exist in the namespace 'TenForce.Execution.Web' (are you missing an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj] [10:38:55]: [exec] Modules\SecurityModuleTests.cs(197,39): error CS0246: The type or namespace name 'SecurityModule' could not be found (are you missing a using directive or an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj] [10:38:55]: [exec] TranslateTests.cs(10,30): error CS0234: The type or namespace name 'Utils' does not exist in the namespace 'TenForce.Execution.Web' (are you missing an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj] [10:38:55]: [exec] IPETests.cs(8,30): error CS0234: The type or namespace name 'Ajax' does not exist in the namespace 'TenForce.Execution.Web' (are you missing an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj] [10:38:55]: [exec] Pages\BasePageTest.cs(6,30): error CS0234: The type or namespace name 'Utils' does not exist in the namespace 'TenForce.Execution.Web' (are you missing an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj] [10:38:55]: [exec] Pages\BasePageTest.cs(7,30): error CS0234: The type or namespace name 'Pages' does not exist in the namespace 'TenForce.Execution.Web' (are you missing an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj] [10:38:55]: [exec] ServiceAsmxTests.cs(9,30): error CS0234: The type or namespace name 'Ajax' does not exist in the namespace 'TenForce.Execution.Web' (are you missing an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj] [10:38:55]: [exec] ServiceAsmxTests.cs(10,30): error CS0234: The type or namespace name 'Utils' does not exist in the namespace 'TenForce.Execution.Web' (are you missing an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj] [10:38:55]: [exec] Pages\BasePageTest.cs(16,17): error CS0246: The type or namespace name 'basepage' could not be found (are you missing a using directive or an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj] [10:38:55]: [exec] ServiceAsmxTests.cs(22,17): error CS0246: The type or namespace name 'Service' could not be found (are you missing a using directive or an assembly reference?) [C:\Robinson\trunk\Projects\Robinson\TenForceExecutionTests\TenForceExecutionTests.csproj] [10:38:55]: [exec] [10:38:55]: [exec] 2075 Warning(s) [10:38:55]: [exec] 10 Error(s) [10:38:55]: [exec] [10:38:55]: [exec] Time Elapsed 00:01:40.06 

TenForceExecutionTests项目是一个简单的DLL,它包含MBunit Framework的几个UnitTests。 该项目引用了TenForceExecution ,它是一个Web应用程序项目,另一个引用TenForce.Execution.Test ,这是另一个包含两个项目逻辑的DLL。

当我们在开发机器上编译所有内容时,它可以正常工作并且编译发生时没有错误。 然而,在构建代理上,这似乎失败了……

信息

  • 目标框架:.NET4
  • 操作系统:Windows XP 32位
  • 已安装Windows 7 SDK

编辑

做了干净的结账,Visual Studio能够构建整个解决方案,但是msbuild不能。

编辑2

检查依赖项:

  • 项目之间存在项目依赖关系
  • 项目之间存在解决方案依赖关系

编辑3当我删除对webApplication项目的引用,并将其替换为对该项目的已编译DLL的引用时,错误消失,并且项目与MSBuild编译良好。

编辑4我已经从msbuild通过LOG运行了整个构建,并查看了编译给出问题的项目的具体任务:

  Task "Csc" c:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\ThirdPartyComponents\ASP.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\BUL\bin\Debug\BUL.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\BULTest\bin\Debug\BULTest.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\DAL\bin\Debug\DAL.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\Framework\bin\Debug\Framework.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\ThirdPartyComponents\Gallio.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\ThirdPartyComponents\Iesi.Collections.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\LanguageResource\bin\Debug\LanguageResource.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\ThirdPartyComponents\log4net.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\ThirdPartyComponents\MbUnit.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll" /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\ThirdPartyComponents\NHibernate.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\PresentationBridge\bin\Debug\PresentationBridge.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\PresentationBridgeTest\bin\Debug\PresentationBridgeTest.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Configuration.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.dll" /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\ThirdPartyComponents\System.Data.SQLite.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.Web.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.Extensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.Services.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.dll" /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\TenForce.Execution.Test\bin\Debug\TenForce.Execution.Test.dll /reference:D:\Users\arne.de.herdt.TENFORCE2\Documents\RobinsonSource\Projects\Robinson\ThirdPartyComponents\WatiN.Core.dll /debug+ /debug:full /optimize- /out:obj\Debug\TenForceExecutionTests.dll /target:library Modules\SecurityModuleTests.cs TestRunSetup.cs TranslateTests.cs WebBaseTest.cs MetaTests.cs IPETests.cs Pages\BasePageTest.cs Properties\AssemblyInfo.cs ServiceAsmxTests.cs Settings.Designer.cs "D:\Users\arne.de.herdt.TENFORCE2\AppData\Local\Temp\6\.NETFramework,Version=v4.0.AssemblyAttributes.cs" Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1 Copyright (C) Microsoft Corporation. All rights reserved. 

据我所知,实际的WebApplication 包含在参考列表中。

今天遇到同样的问题,结束了无法引用的项目指定了不同的平台, x86其中任何平台的其他项目。 为了解决这个问题,我必须使用/ p:Platform =“Mixed Platforms”设置参数。 您可以通过转到Configuration Manager并查看右上角选择的Active Solution Platform来查看VS使用的内容。

显然这似乎是MSBuild中的一个已知问题,因为更多人对此有疑问。 我还没有收到微软的有效回复,但讨论仍在继续: http : //social.msdn.microsoft.com/Forums/en-CA/msbuild/thread/434abf1a-30db-4b13-8062 -13755898dd71

我知道这是一个老post,但我今天遇到了它,所以我想我会为其他人提供反馈。

我已经遇到过这种情况,发现将目标框架从.NET Framework 4 Client Profile更改为.NET Framework 4就可以了。

如果您对机器上的新文件夹进行了干净的检查,那么它也可以在那里工作吗?

大多数情况下会出现这些问题,因为您可以引用本地可用但不在源代码管理中的内容。 这是一个很好的检查,以查看构建项目所需的所有内容是否已正确引用并在源代码管理下。

我也遇到过这样的问题:从VS构建并不总是与使用msbuild相同。 那么帮助我的是创建msbuild运行日志(/ fl开关)并检查日志并追踪构建步骤并尝试找到有问题的任务。

我检查错过的dll属性,我看到程序集名称与默认命名空间的名称相同。 然后我将程序集名称更改为另一个名称,我解决了我的问题。

我也经历过同样的问题。

我真的怀疑为什么MSBuild会在我们通过MSBuild和Jenkins运行解决方案文件时抛出缺少的程序集引用,但它在Visual Studio中就像一个魅力,经过两天的战斗我得到了一个结论。

我编写了一个批处理脚本,首先通过Visual Studio运行解决方案文件,然后运行解决方案文件。 它工作不正常。

您需要做的就是调用批处理脚本,然后运行MSBuild / Jenkins。

批处理脚本:

cd C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE devenv“C:\ Program Files(x86)\ Jenkins \ workspace \ TFS \ Product \ Soluttion.sln”/ Rebuild

devenv:在命令行中运行Visual Studio。

注意:如果您在服务器中运行MSBuild / Jenkins,则确实需要Visual Studio。

如有任何相关问题,请寄给我……….

我在发布模式下使用MSBuild构建解决方案时遇到此错误消息,即使调试模式工作正常并且都在Visual Studio中工作。 在解决方案设置中,项目未配置为“Release | Mixed Platforms”或“Release | Any CPU”构建。

我尝试过使用AnyCPU和Prefer-32位,它仍然无效。 也尝试使用AnyCPU而不检查Prefer-32位但没有任何效果。 使用Bamboo部署代码时出现此问题。 我确保我的包都签入了代码 (因为我的竹子中的nuget恢复有问题)并确保我在项目中的dll引用正在查看其路径中的包。 我通过从.gitignore文件中删除/ packages来检查我的包。 另外,更新了我在项目中的packages.config文件,提到了包和要使用的版本。 对于Ex: 此外,确保运行部署任务的代理程序具有所需的.NET框架版本。 通过上述所有更改,我可以解决此参考问题。