1
votes

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.

1
Fix the HintPath properties in the .csproj files - KMoraz
The missing references are my own projects that are part of the solution. They show up as ProjectReference in the .csproj files, and they contain relative paths, like this: <ProjectReference Include="..\..\MyProject\MyProject.csproj"> - Nick Corley
As I said, it succeeds almost half the time. I can also open the solution source code that is pulled to the build server and build it myself in Visual Studio just fine. - Nick Corley
What you should do is set the build log verbosity to "diagnostic" so when a case falls in the 60%, then you can open the log and get specifics. - Nicodemeus
@Nicodemeus I've added to the post with the diagnostic logs - Nick Corley

1 Answers

3
votes

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.