Building from the command line != building from the IDE
I just spent the last several hours fixing a large number of assembly references in a big C# solution. That means lots of errors like the following that leave you grep’ing your way through .sln/.csproj files to figure out what’s gone wrong:
Solution file warning MSB4051: Project {A9E00AF7-A1E0-4E65-90EF-CB66E8580
9AE} is referencing a project with GUID {958E0376-0272-4149-A1CF-E03521D12A72}, but a project with this GUID was not found in the .SLN file.
And builds stats that look like this:
Not good. It doesn’t help when VS.NET itself can cause these problems yet continue on blissfully. What I ran into today was a different reason for the same error message, this time around it wasn’t a missing "EndProject". The issue was that the second GUI was referring to a project that not only wasn’t in the .sln file but no longer existed. Regardless, the outcome was the same, building from VS.NET worked but executing MSBuild from the command line failed. WHY?! IMO, VS.NET should have failed just like MSBuild because it’s not doing you any favors when it doesn’t fail consistently along with MSBuild rather that’s just masking a problem. In addition, the error could be improved to show better information about the GUIDs that do reference a project rather than the GUID itself. I couldn’t agree more with Jeff Atwood’s post title The F5 Key Is Not a Bulid Process where he says:
If your "build process" is the F5 key, you have a problem. ...
Get your build process out of the IDE and into a build script. That’s the first step on the road to build enlightenment.
Amen.
Communicating Continuous Integration Requirements
If you’re chasing the holy grail of CI and working to get automated builds, test execution, static code analysis, build stats etc. make sure the developers working on the project understand the build requirements of your CI setup. In this case, building the main project is about as straight forward as it gets:
%SystemRoot%\Microsoft.NET\Framework\v3.5\msbuild /t:clean mysolution.sln
%SystemRoot%\Microsoft.NET\Framework\v3.5\msbuild /t:build mysolution.sln Like I said, simple. Now, on the build server itself things aren’t quite this simple but for the bulk of the build if you get by this step you’ve gone a long way as it builds 22 C# projects. The first line above, that cleans the build is crucial. If you skip it and build from the command line after building in VS.NET you’ll continue masking the problem. A successful clean process is just as important as a successful build process. On this particular project there was a major project renaming that introduced a slew of errors but the VS.NET IDE sat idly by and in fact allowed this problem to occur. Eventually a checkin that trigger this set of failures occurred all the while "it builds fine on my machine".
The second problem was solution file name changes, copy/renames to be more specific, which further broke the CI build. The third problem was that the old .sln and csproj files were not deleted from the repository which led to even more confusion but I digress, that’s life in the real world, we fix it and move on.