Question

Is there way to issue one command line to build a solution with all it's configurations?

Currently we have 5 configurations, so we need to issue the 5 commands in the following format:

C:\Program Files\Microsoft Visual Studio 10.0\VC>devenv /Rebuild [configuration name] C:\Solutions\SolutionName.sln

such as:

devenv /Rebuild Debug C:\Solutions\SolutionName.sln
devenv /Rebuild DEV C:\Solutions\SolutionName.sln
devenv /Rebuild SIT C:\Solutions\SolutionName.sln
devenv /Rebuild BAT C:\Solutions\SolutionName.sln
devenv /Rebuild PROD C:\Solutions\SolutionName.sln

Ideally just have one command line. I tried unsuccessfully putting all the configuration names together, space delimited.

Was it helpful?

Solution

There is no syntax (that I know of, and that I could discover through testing) to build more than one configuration at a time. The configuration property in MSBuild doesn't appear to support multiple values, either.

Why not just put the commands you need into a batch file, powershell script, or even another MSBuild file and launch that?

OTHER TIPS

Try to use solution-level platform called "Mixed Platforms". See this post. This is helpful if you have more configurations and every project is using the different configuration.

  msbuild.exe MixedProjects.sln /p:"Platform=Mixed Platforms" /p:Configuration=Debug

Dunno, maybe would be useful for someone:

BuildVCSolution.js

var objNamedArguments = WScript.Arguments.Named;
var objUnnamedArguments = WScript.Arguments.Unnamed;
var fKeepSUO = objNamedArguments.Exists("KeepSUO");
if (objNamedArguments.Length > 1 || (objNamedArguments.Length == 1 && fKeepSUO == false) || objUnnamedArguments.Length != 1)
{
    WScript.Echo("\nUsage: " + WScript.ScriptName + " <Solution Pathname> [/KeepSUO]\n");
    WScript.Quit();
}
var objFSO =  WScript.CreateObject("Scripting.FileSystemObject");
var strSolutionPathName = objFSO.GetAbsolutePathName(objUnnamedArguments(0));
var objDTE = WScript.CreateObject("VisualStudio.DTE");
var objTextEditorCAndCPPDisableDatabaseProperty = objDTE.Properties("TextEditor", "C/C++ Specific").Item("DisableDatabase");
var fDisableDatabase = objTextEditorCAndCPPDisableDatabaseProperty.Value;
objTextEditorCAndCPPDisableDatabaseProperty.Value = true;
var objSolution = objDTE.Solution;
objSolution.Open(strSolutionPathName);
var objSolutionBuild = objSolution.SolutionBuild;
var objSolutionBuildConfigurations = objSolutionBuild.SolutionConfigurations;
var objBuildOutputWindowPane = objDTE.Windows.Item("{34E76E81-EE4A-11D0-AE2E-00A0C90FFFC3}").Object.OutputWindowPanes.Item("Build");
objBuildOutputWindowPane.Activate();
for (var i = 0; i < objSolutionBuildConfigurations.Count; i ++)
{
    var objSolutionBuildConfigurationContexts = objSolutionBuildConfigurations.Item(i + 1).SolutionContexts;
    for (var j = 0; j < objSolutionBuildConfigurationContexts.Count; j ++)
    {
        var objSolutionBuildConfigurationContext = objSolutionBuildConfigurationContexts.Item(j + 1);
        if (objSolutionBuildConfigurationContext.ShouldBuild)
        {
            var strSolutionBuildConfigurationFullName = objSolutionBuildConfigurationContext.ConfigurationName + "|" + objSolutionBuildConfigurationContext.PlatformName;
            objSolutionBuild.BuildProject(strSolutionBuildConfigurationFullName, objSolutionBuildConfigurationContext.ProjectName, true);
            WScript.Echo(objBuildOutputWindowPane.TextDocument.StartPoint.CreateEditPoint().GetText(objBuildOutputWindowPane.TextDocument.EndPoint));
        }
    }
}
objSolution.Close();
objTextEditorCAndCPPDisableDatabaseProperty.Value = fDisableDatabase;
objDTE.Quit();
if (fKeepSUO == false)
{
    var strSUOPathName = objFSO.BuildPath(objFSO.GetParentFolderName(strSolutionPathName), objFSO.GetBaseName(strSolutionPathName)) + ".suo";
    objFSO.DeleteFile(strSUOPathName);
}

This WSH script demonstrates usage of Visual Studio 2010 core Automation object model for building projects. The main goal of this script — is to build a solution with all it's projects configurations via one command line. Additional techniques are used to show build log and suppress creation of .sdf and .suo files (optionally .suo file can be kept).

Usage:

cscript.exe BuildVCSolution.js <Solution pathname>

or just

BuildVCSolution.js <Solution pathname>

if cscript.exe is the default script host server.

For example:

BuildVCSolution.js "D:\Development\Projects\Sample Application\SampleApplication.sln"

Tested with Visual Studio 2010 SP1 on Windows 7 x64 SP1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top