R – Why does VS2008 build differ from msbuild for same solution

continuous integrationmsbuildvisual-studio-2008

I have inherited a solution consisting of several projects, a mix of VB.NET and C#. It builds fine using the IDE "Build Solution" button. It does not build from the command line using "msbuild foo.sln"; the error message indicates that project A (which references project B) can't find project B. Indeed, upon examining the contents of the "bin" folder after using "msbuild" and comparing it against the contents after using the IDE, I can find a whole lot of DLLs missing, including B.dll.

In short: the project A does have a reference to project B, but B.DLL is only copied to A's bin directory when using the IDE, but not when using msbuild. If I run msbuild after an IDE build it works, since the referenced DLLs are copied.

I had naively believed that "msbuild foo.sln" is the same as an IDE build of foo.sln. That doesn't seem to be the case. There are at least three other similar questions here on Stack Overflow but I can't reference them because "new users can only post one hyperlink" (!!). Sorry. Here are the question titles so you can search yourself:

Now here are my questions:

  1. Where can I find documented precisely what Visual Studio does when you "Build Solution"?
  2. What are the best practices for configuring Visual Studio and a Continuous Integration server (e.g. Hudson) so that the developer workstation builds are the same as the CI builds?

I'm coming from the unix world, so feel free to send me newbie pointers.

Best Answer

John Weldoon is correct the builds from Visual Studio and MSBuild are very similar but can be different at times. One case is that VS is more lienent with respect to referecnes. Lets say you have three projecta A, B and C. A depends on B and B depends on C. Then in VS if project A just references B then its OK but MSBuild may complain because it is missing a reference to project C. One of the big reasons that there is some difference is because VS has a host compilier that is used to help enahce the IDE experience. If you are wiling to downgrade your IDE experience then you can set the MSBuild property, UseHostCompilerIfAvailable, to false to force Visual Studio to use MSBuild. Such as

<PropertyGroup>
    <UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>
</PropertyGroup>

I don't suggest this but if you absolutely need it the option is available to you.