Visual Studio builds loaded projects only when building solution from command line
One of my Visual Studio 2010 solutions has a comparatively larger number of projects (more than 30). And we use PowerShell scripts extensively to automate many build and packaging tasks for this solution.
For example, the main PowerShell build script rebuilds all the projects in the solution, minifies js/css resources from various projects, packages various projects as stand-alone installable modules and packages the main project as an installer/updater.
The main reason we chose to use Visual Studio's command-line for the build (and not msbuild) was the availability to pre/post build macros when the projects are built through Visual Studio. We were using the following command to build the entire solution from PowerShell:
&"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" "D:\Projects\SomeProject\ProjectName.sln" /rebuild Debug | Out-Null;
However when I inspected the various installer packages created by our PS build script, I noticed some of the assemblies in the installer packages were not up-to-date (but contained an older build of that assembly). That came across as a bit of surprise as the above command was supposed to build all projects in the solution and the build script was then supposed to pick updated assemblies and add them to the installer packages.
After some investigation, it appeared that the build script was picking up the stale version of those assemblies whose projects were unloaded in Visual Studio from the solution (the reason these projects were unloaded was obviously for enhanced development experience and minimizing build time during development). Adding some echo commands to project post-builds confirmed that the projects which were unloaded were not built when the build was invoked from command-line.
Although it came as a surprise initially, it appeared pretty logical afterwards. The VS command-line build is supposed to behave exactly similar to how regular point-and-click builds work from UI. As VS does not build unloaded projects when build is invoked from UI, it won't build these projects when build is invoked from command-line.
The solution (I mean the problem's solution, not the VS solution )was pretty simple. We just added another (VS) solution file and ensured all output projects (excluding the Test and development helper projects) were added to this new solution and were loaded in this new solution (let's call it ProjectName-Publish.sln) and then we updated our build script to build using this new solution:
&"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" "D:\Projects\SomeProject\ProjectName-Publish.sln" /rebuild Debug | Out-Null;
This has worked prettty well since then. The only thing we need to take care of is to make sure any new project added to the original solution (which happens every month or two as the overall project is still under intense development) has to be added to the Publish solution too if the output of that project has to be supplied in any of the installer/updater packages.