我目前正在试图找出为什么MSBuild无法编译我们的单元测试dll。这个问题只发生在这个DLL而不是其他单元测试项目中。
这是我在构建失败时从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。
当我们在开发机器上编译所有内容时,它可以正常运行并且编译没有错误。然而,在构建代理上,这似乎失败了......
的 INFO 的
修改 的
干净的结帐,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是 NOT 包含在参考列表中。
答案 0 :(得分:5)
今天遇到同样的问题,结束了无法引用的项目指定了不同的平台, x86 其中 Any Platform 的其他项目。为了解决这个问题,我必须使用 / p:Platform =" Mixed Platforms" 设置参数。您可以通过转到Configuration Manager并查看右上角选择的 Active Solution Platform 来查看VS使用的内容。
答案 1 :(得分:3)
显然,这似乎是MSBuild中的已知问题,因为更多人对此有疑问。 我仍然没有收到微软对此的有效回复,但讨论仍在继续:http://social.msdn.microsoft.com/Forums/en-CA/msbuild/thread/434abf1a-30db-4b13-8062-13755898dd71
答案 2 :(得分:2)
我知道这是一个老帖子,但我今天遇到了它,所以我想我会为其他人提供反馈。
我已经遇到过这种情况,发现将目标框架从.NET Framework 4 Client Profile更改为.NET Framework 4就可以了。
答案 3 :(得分:1)
在构建UWP appx软件包时,我还发现了类似的参考问题。有很多错误消息看起来像:
App.xaml.cs(6,15): error CS0234: The type or namespace name 'ApplicationModel' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
如果使用VS2017打开sln文件,则不会产生任何问题。
我做了两件事来解决此问题:
msbuild mySolution.sln /p:Configuration="Release" /p:Platform="x64" /t:restore
msbuild mySolution.sln /p:Configuration="Release" /p:Platform="x64"
有关还原,请参阅https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#restore-target
答案 4 :(得分:1)
我遇到了同样的问题(在 Visual Studio 中成功构建,但由于 MSBUILD 而失败)。
尝试了此问题中提到的其他解决方案,但失败了。
幸运的是,最后我发现添加 -tv:version 可以解决错误。
对于我的项目,A.csproj中的<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
是v4.0,因此我使用了msbuild A.csproj -tv:4.0
这样的命令,然后成功编译了项目。
下面是我的解决方案的结构:
项目A:启动项目和目标框架version = v4.0
项目B:参考项目,其目标框架版本为v3.5
项目C:参考项目,其目标框架版本为v3.5
如果在存在多个版本时,如果不告诉特定目标框架版本为 MSBUILD ,有时会被弄乱。
答案 5 :(得分:0)
如果您对机器上的新文件夹进行了干净的检查,那么它也可以在那里工作吗?
大多数情况下会出现这些问题,因为您可以引用本地可用但不在源代码管理中的内容。这是一个很好的检查,以查看构建项目所需的所有内容是否正确引用并在源代码管理下。
答案 6 :(得分:0)
我也遇到过这样的问题:从VS构建并不总是与使用msbuild相同。那么帮助我的是创建msbuild运行日志(/ fl开关)并检查日志并追踪构建步骤并尝试找到有问题的任务。
答案 7 :(得分:0)
我检查错过的dll属性,我看到程序集名称与默认命名空间的名称相同。 然后我将程序集名称更改为另一个名称,我解决了我的问题。
答案 8 :(得分:0)
我也经历过同样的问题。
我真的怀疑为什么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。
如有任何相关问题,请发邮件给我..........
答案 9 :(得分:0)
我在发布模式下使用MSBuild构建解决方案时遇到此错误消息,即使调试模式工作正常并且都在Visual Studio中工作。在解决方案设置中,项目未配置为“Release | Mixed Platforms”或“Release | Any CPU”构建。
答案 10 :(得分:0)
我尝试使用AnyCPU和Prefer-32位,但仍然无法正常工作。也尝试使用AnyCPU而不检查Prefer-32位,但是没有任何效果。使用Bamboo部署代码时遇到了这个问题。我确保将所有软件包都签入到代码中(因为我在Bamboo中进行的nuget恢复存在问题),并确保我在项目中的dll引用正在查看其路径中的软件包。我通过从.gitignore文件中删除 / packages 来签入我的软件包。另外,更新了项目中的我的packages.config文件,以提及软件包和要使用的版本。 例如: 另外,请确保正在运行部署任务的代理具有所需的.NET框架版本。通过上述所有更改,我可以解决此参考问题。
答案 11 :(得分:0)
我的项目配置文件“ csproj ”具有两个
当我合并这些
答案 12 :(得分:0)
在 Visual Studio 2019 项目中遇到了同样的问题。
问题已通过将项目引用从 packages.config 迁移到 PackageReference 解决。
<块引用>使用 localeCompare
打开包含项目的解决方案。
在解决方案资源管理器中,右键单击引用节点或valueOf
文件,然后选择将packages.config迁移到PackageReference ....
[...]
<块引用>注意
在迁移开始之前,Visual Studio 会创建项目的备份,以允许您在必要时回滚到 packages.config。