Nick Corley
Nick Corley

Reputation: 41

MSBuild fails with missing references sometimes

I have created a build in TFS 2013, using VS 2013. My solution builds correctly in Visual Studio, and I can open the solution from the drop folder on the build server and compile it as well.

The problem is that a triggered build will fail randomly, maybe around 60% of the time, with missing reference errors. The missing references are only my own projects that are built with the solution, not packages or Microsoft dlls. The number of actual missing reference errors varies as well, leading me to believe that the problem is related to file access handles. The build fails with the standard "MSBuild error 1". Here is an example error:

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?)

As I said, the project builds fine in Visual Studio, but I checked dependencies on the solution anyway, and everything appears to be correct.

It may be worth noting that I am using TFS's Git implementation, so my build process file is currently GitTemplate.12.xaml. This file works fine for several other similar solutions I am working on.

Edit: I opened the more detailed build logs and here is the section that happened to fail in this instance:

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]

Here is the same section when the build succeeds:

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:

It appears that the namespace can't be found because the reference is not included in the command line arguments for csc.exe.

What would cause a build command to be randomly malformed? Could it be resources on the build machine? Something in the build process template?

Edit 2: Here is an example of a project reference in the .csproj file of the project that caused the build failure in my posted error log:

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

This path is the same on my machine and the build machine since both versions are cloned from the same Git repository.

Upvotes: 1

Views: 2509

Answers (1)

Nick Corley
Nick Corley

Reputation: 41

I had several projects in my solution that were building with different target frameworks, and each referenced the same library (Newtonsoft.Json). With dependencies, the basic setup was this:

Project A (target framework .net 4.5) referenced Project B.

Project A referenced Project C (target framework .net 4.5).

Project B (target framework .net 4.0) referenced Project C (target framework .net 4.0).

I was getting a warning, but Visual Studio built the solution. MSBuild would fail randomly, only showing the warning when it failed. I don't know why the random element was there, but the workaround was to make sure every library in my solution was referenced with the same target framework. This included updating packages.config and the .csproj files to point to the same location.

Upvotes: 3

Related Questions