views:

269

answers:

2

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.

A: 

In my opinion you should build your CI scripts, and general build scripts with msbuild.

The IDE does not use the same engine for building all the time as the msbuild engine, although I think they are working on doing it more and more.

John Weldon
+1  A: 

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.

Sayed Ibrahim Hashimi
As to the transitive closure problem: I do have project A depending on both B and C, as well as project B depending on C. Still fails.
Steve Robbins
Good answer, I hate the fact that visual studio doesn't use msbuild exclusively, it creates all sorts of issues on continuous build servers etc, where people use .sln file as a build file rather than handcrafting their own, I often set the UseHostCompilerIfAvailable to false, but I tend only to do that when doing a final build before committing to the repository.
krystan honour