How do I build all configurations of a project from the command line?

By Stephen Kellett
24 November, 2023

The problem

I needed an easy way to automate the building of a Visual Studio project from the command line. It needed to work regardless of which Visual Studio the project file was from. Visual Studio 2022 through Visual Studio 6. That’s three different project file formats (.dsp, .vcproj and .vcxproj) and three different Visual Studio command line styles (msdev.exe, devenv.exe and msbuild.exe).

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.

A few months back we upgraded Visual Studio Project Builder to build all projects in a solution from the command line. I thought adding the same functionality to handle projects would be a good idea.

Time for an upgrade for Visual Studio Project Builder.

/buildProject

We’ve added the /buildProject option to Visual Studio Project Builder. Specify /buildProject path-to-project.vcxproj, and use quotes to surround any path containing spaces.

Examples:

visualStudioProjectBuilder.exe /vcxproj /buildProject e:\om\c\testApp\testApp.vcxproj

visualStudioProjectBuilder.exe /vcxproj /buildProject “e:\om\c\dev workspace\testApp\testApp.vcxproj”

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

/buildProject 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 specify the same project file types as the project. Choose one of:

/vcxproj
/vcproj
/dsp
/csproj
/fsproj
/vbproj
/vjsproj

Batch file usage

start /wait “Build TestApp” “C:\Program Files (x86)\Software Verify\Visual Studio Project Builder\visualStudioProjectBuilder.exe” /vcxproj /buildProject “e:\om\c\testApp\testApp.vcxproj”

This line in the batch file does this:

  • starts Visual Studio Project Builder
  • resets the settings to the default
  • loads e:\om\c\testApp\testApp.vcxproj (you can specify other project types)
  • builds all configurations of the project (which 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

 

Fully functional, free for 30 days