How to build all configurations of a Visual Studio project from the command line?
Automating the building of a Visual Studio project can save significant time and reduce errors, especially when dealing with large projects or frequent updates. One common approach is to use a build command from the command prompt on Windows, which allows you to build project files directly without opening the Visual Studio IDE.
Manually opening Visual Studio and building each project or solution is tedious and inefficient.
Visual Studio Project Builder is a tool designed to help automate these tasks. Additionally, build commands can be executed from the command prompt or batch files on Windows, making it easier to integrate automated builds into your development process.
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
To build a project with Visual Studio Project Builder we’ve added the /buildProject option.
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
You’re going to want to use the appropriate settings file when building your projects. Load the settings file with /loadSettings.
Specify /loadSettings path-to-settings.vspbs, and use quotes to surround any path containing spaces.
Examples:
Alternatively, you can use/resetSettings to use the default settings to build the solution.
You can also specify the same project file types as the project. Choose one of:
/vcxproj
/vcproj
/dsp
/csproj
/fsproj
/vbproj
/vjsproj
Batch file usage
To work with batch files you’ll need to specify the type of project file and the project file name, plus any optional arguments.
/vxproj Use a modern Visual Studio file format
/buildproject path-to-project-name load project file
/wait instruct the batch file to wait until Visual Studio Project Builder has closed
/resetSettings resets the settings to default
/loadSettings “e:\my settings\settings.vspbs” load settings from a file
Example 1:
start /wait “Build TestApp” “C:\Program Files (x86)\Software Verify\Visual Studio Project Builder\visualStudioProjectBuilder.exe” /resetSettings /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 /resetSettings
- loads the Visual Studio project 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 /wait
Example 2:
start /wait “Build TestApp” “C:\Program Files (x86)\Software Verify\Visual Studio Project Builder\visualStudioProjectBuilder.exe” /loadSettings “e:\my settings\settings.vspbs” /buildProject “e:\om\c\testApp\testApp.vcxproj”
This line in the batch file does this:
- starts Visual Studio Project Builder
- loads settings from e:\my settings\settings.vspbs
- loads the Visual Studio project e:\om\c\testApp\testApp.vcxproj
- 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/wait