How do I build all projects in a solution from the command line?
The problem
I needed an easy way to automate the building of a Visual Studio solution from the command line.
I have a process that consists of 8 separate tasks, each of which consists of multiple similar actions on different datasets. I was doing this manually, which gets the job done, but eats my time. I wanted to automate this, to reduce error and free up my time. Part of this process was building 21 solutions – all of the example project solutions that ship with our Validator tools.
We have Visual Studio Project Builder, which is an interactive tool that can build large collections of Visual Studio projects and solutions, but I couldn’t use it to automate this task because I needed to interact with the user interface a few times during the process.
Time for an upgrade for Visual Studio Project Builder.
/buildSolution
We’ve added the /buildSolution option to Visual Studio Project Builder. Specify /buildSolution path-to-solution.sln, and use quotes to surround any path containing spaces.
Examples:
visualStudioProjectBuilder.exe /vcxproj /buildSolution e:\om\c\testApps\testApps.sln
visualStudioProjectBuilder.exe /vcxproj /buildSolution “e:\om\c\dev workspace\testApps\testApps.sln”
The Visual Studio Project Builder user interface is shown during the build process so that you can see the progress of the build. There is no need for you to interact with the user interface, it will close automatically at the end of the build.
Settings
/buildSolution is best used with /loadSettings to load the settings you wish to use to build the solution, or with /resetSettings to use the default settings to build the solution.
Alternatively you can specify individual project file types to build in the solution:
/vcxproj
/vcproj
/dsp
/csproj
/fsproj
/vbproj
/vjsproj
Batch file usage
start /wait “Build TestApps” “C:\Program Files (x86)\Software Verify\Visual Studio Project Builder\visualStudioProjectBuilder.exe” /resetSettings /buildSolution “e:\om\c\testApps\testApps.sln”
This line in the batch file does this:
- starts Visual Studio Project Builder
- resets the settings to the default
- loads e:\om\c\testApps\testApps.sln
- builds all configurations of all projects in the solution (which projects and configurations are controlled by the settings – you can change this by using /loadSettings)
- closes Visual Studio Project Builder
- the batch file waits for Visual Studio Project Builder before executing the next statement in the batch file