MSBuild cannot find a reference

2019-02-16 09:10发布

I'm currently trying to figure out why MSBuild is not able to compile one of our unit test dlls. The problem is only occuring with this DLL and not with the other unit test projects.

This is the output I receive from TeamCity when the build fails:

[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

The project TenForceExecutionTests is a simply DLL that contains several UnitTests of the MBunit Framework. This project has a reference to TenForceExecution which is a web application project and another reference to TenForce.Execution.Test, which is another DLL containing logic for both projects.

When we compile everything on the development machine, it works without problems and the compile occurs without errors. On the build agent however this seems to fail...

INFO

  • Target Framework : .NET4
  • OS : Windows XP 32bit
  • Windows 7 SDK Installed

EDIT

Did a clean checkout, and Visual Studio is able to build the entire solution, msbuild however cannot.

EDIT 2

Checked the dependencies:

  • There is a project dependency between the projects
  • There is a solution dependecy between the projects

EDIT 3 When I remove the reference to the webApplication project, and replace it with a reference to the compiled DLL of that project, the errors dissapear and the project compiles fine with MSBuild.

EDIT 4 I've ran the entire build from msbuild through a LOG and took a look at the specific task for compiling the project that's giving problems:

  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.

From what I can tell, the actuall WebApplication is NOT included in the reference list.

9条回答
爷的心禁止访问
2楼-- · 2019-02-16 09:28

I have also experienced the issue that building from VS is not always the same as simply using msbuild. What helped me then is to create a log of the msbuild run (/fl switch) and check the log and trace down the build steps and try to find the problematic task.

查看更多
爷、活的狠高调
3楼-- · 2019-02-16 09:33

I have also experienced the same issue.

I really doubt why MSBuild throws missing assembly reference when ever we run the solution file through MSBuild and Jenkins but it works like a charm in the Visual Studio, After fighting for two days I found a conclusion for this.

I wrote a batch script to run the Solution file first through Visual Studio and then ran the Solution file. It is not working fine.

All you need to do is to call the batch script and then run the MSBuild/Jenkins.

Batch script :

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: To run the Visual Studio in Command line.

Note: you really need Visual Studio if your running MSBuild/Jenkins in the server.

Mail me for any issues regarding this..........

查看更多
Anthone
4楼-- · 2019-02-16 09:40

I know this is an old post, but I came across it today, so thought I would offer feedback for anyone else.

I've encountered this a few times and found that changing the Target Framework from .NET Framework 4 Client Profile to just .NET Framework 4 does the trick.

查看更多
冷血范
5楼-- · 2019-02-16 09:42

I have tried using AnyCPU and Prefer-32 bit, it still didn't work. Also tried with AnyCPU without checking Prefer-32 bit but nothing worked. I was having this issue when Deploying my code using the Bamboo. I made sure my packages are all checked in to the code(as my nuget restore in bamboo have an issue) and make sure my dll references in the project are looking at the packages in their paths. I checked in my packages by removing the /packages from the .gitignore file. Also, updated my packages.config file in the project to mention the package and the version to use. For Ex: Also, made sure the Agent on which the Deployment task is running, it has the needed .NET framework version. With the above all changes, I could resolve this reference issue.

查看更多
做个烂人
6楼-- · 2019-02-16 09:44

I encountered this error message when I built a solution with MSBuild in Release mode, even though Debug mode worked fine and both worked in Visual Studio. Turned out in the solution settings the project was not configured to be built for "Release|Mixed Platforms" or "Release|Any CPU".

查看更多
迷人小祖宗
7楼-- · 2019-02-16 09:45

I inspect the dll properties missed and I see that the assembly name have the same name of the default namespace. Then I change the assembly name to a different one and I solved my problem.

查看更多
登录 后发表回答