VCBuild vs. C++ MSBuild on the Command Line

VCBuild vs. C++ MSBuild on the Command Line

  • Comments 11

In Visual Studio 2010, the command line tool vcbuild.exe will be replaced by msbuild.exe. The executable change does mean switches will change, too.  To help make the migration easier, I have created this table as a quick guide to the new switches and highlight some differences between the tools.  The table below isn’t a complete table of all the switches provided in both tools.

Migrating to MSBuild requires a new project type with a different extension (vcxproj).  Visual Studio comes with two tools for converting existing projects and solutions.  When dealing with a single project, the “vcupgrade.exe <filename>.vcproj” tool provides a quick conversion.  When dealing with multiple projects in a solution, use devenv to converts the whole solutions (.sln) and all of the projects within.  Once the project or solution has been converted without errors, you can use MSBuild.

When invoked with no explicit project configuration, VCBuild used to build all Configuration and Platform matrix by default, MSBuild, in contrast, builds only the default “Debug | Win32”.

In MSBuild, any feature that is enabled by /p[roperty] switch can also be enabled by setting the environment variable with the respective name.  For an example, “set Configuration=Debug” in the command line is the same as passing “/p:Configuration=Debug” to all MSBuild execution.

[] = optional characters to help remember the switch

Build Project

VCBuild.exe <projectname.vcproj>

MSBuild.exe <projectname.vcxproj>

Build Solution

VCBuild.exe <solutionname.sln>

MSBuild.exe <solutionname.sln>

Rebuild

/rebuild

/t[arget]:rebuild

Clean

/clean

/t[arget]:clean

Use Environment variables for INCLUDE and LIB

/useenv

/p[roperty]:useenv=true

Multi-processor build *

/m#

/m:#

Platform

/platform:<platform>

/p:Platform=<platform>

Configuration

<configuration>

/p:Configuration=<configuration>

Force Link (Link will always execute)

/forcelink

/t:BuildLink

Passes

/pass0

/t:BuildGenerateSources

 

/pass1

/t:BuildCompile

 

/pass2

/t:BuildLink /p:BuildType=Build

(BuildType property enables the incremental build tracking)

* Command line build are defaulted to use a single node (/m:1).  We encourage using n nodes where n is equal to the number of cores on the machine. 

MSBuild specific switches

Single File Build (Selected File Build)

Specify the files and tool’s target name that would execute upon the files. **

/t:<toolname> /p:SelectedFiles=”<files>”

 

/t:ClCompile

/p: SelectedFiles=”StdAfx.cpp;main.cpp”

Preprocess project file

Aggregate the project file by inlining all the files that would be imported during a build.  This doesn’t actually perform a build.

/PreProcess<:file> or /pp<:file>

 

/pp:outfile.txt

File logging

Logs the build into msbuild.log. See msbuild help for more information and options.

/FileLogger or /fl

Verbosity

Silence or increase details about the build.

Quiet and would barely show

/V[erbosity]:(q[uiet], m[inimal], n[ormal], d[etailed], or diag[nostic])

Detailed Summary

Provide statistics and summary at the end of build.

/DetailedSummary or /ds

 

** At this time, I can’t provide a list of tools, but there will be a complete list of possible targets on MSDN when it is ready.

If I have missed any options that you feel are important enough to go onto this list, please comment below.  I have left out many possible switches in order to emphasis the commonly used ones.  For further references, consider these links below:

MSBuild Command Line Reference - http://msdn.microsoft.com/en-us/library/ms164311.aspx

VC++ Building on the Command Line - http://msdn.microsoft.com/en-us/library/f35ctcxw%28VS.100%29.aspx

The New VC++ Project/Build system - http://channel9.msdn.com/posts/Charles/Bogdan-Mihalcea-The-New-VC-ProjectBuild-system-MSBuild-for-C/

Felix Huang

VC Project & Build Team

 

  • Just an idea, what if visual studio installed a shell extension that can populate the right-click menu with the configs of any clicked project or solution file and could call msbuild.exe to build the selected.

  • It is not a bad idea, but probably not right to add into Visual Studio as some may see it as a distraction.  A better place too add this is in codeplace as a 3rd party extension.

  • @Gabest: Considering that Explorer is more than wonky enough already, the *last* thing I'd want is more plugins for it. It already crashes or hangs or eats 80% CPU if you even look at it funny.

    Especially as neither the VS team or Explorer ever really seem to have got the hang of the whole "asynchronous" thing, initiating potentially CPU-intensive actions (such as building a solution) from a shell plugin seems like a really painful idea.

    Yeah I know, call me cynical... ;)

  • I have no idea what you are talking about!

  • How could i use VS2010 IDE and newer build system to build my old VS6 project with older libraries.  I read little bit about toolsets in project properties pages that allows to do this with VS2005.  but not sure if this is possible for VS6

  • is this possible??

    <PropertyGroup>

       <PlatformToolset>v60</PlatformToolset>

    </PropertyGroup>

    to build the project against VC++ 6 and corrosponding libraries (inlucding PSDK Jan 2002)?

  • VS2010 will ship with the ability to re-target VS2008.  It re-targets by changing the path and environment variables of tools, libraries, and headers.  In theory, you could write a props to re-target 2005 and older toolset.  Keep in mind that some tools and switches may not exist at the time, so re-targeting may get harder with older toolset.

    There are two ways of affecting project build without modifying the project, msbuild argument (/p:platoformtoolset=v90 ) and environment variable.  

  • Does-it mean that we will be able to compile VC++ projects in a build environment without using devenv and therefore not sacrifice a precious license?

  • I can't comment on the license, but I can say that VC Express and WinSDK has been free for serveral years.  Both of those are capable for building vcproj.

  • The Express edition of the IDE does not support MFC.  I'm not sure if that is a limitation of the C++ compiler or the IDE though.

    My understanding is that msbuild.exe does not require Visual Studio to be installed on the system.  This however says little about licensing restrictions.

  • "Team editions are licensed according to the Microsoft Developer Tools licensing model, which licenses products on a per user basis and each licensed user may install and use the software as many times as they wish on their devices. However, a license for each product is required for each user who uses it on those devices. "

    http://www.microsoft.com/downloads/details.aspx?FamilyId=CE194742-A6E8-4126-AA30-5C4E969AF2A3&displaylang=en

    Please direct further licensing question to http://www.microsoft.com/licensing/ .

    Michael Price, you are correct that MSBuild doesn't require Visual Studio.  However, the project file doesn't contain all the build behavior.  It imports a set of files that is installed via Visual Studio.  You can find the *.targets and *.props in %programfiles%\msbuild\microsoft.cpp\v4.0\

    The VS2010 compiler and the IDE/Build doesn't place any limitation on libraries or headers.  So in theory, you could get any libraries to work.   Granted, some setting may be already set with certain VS versions.

Page 1 of 1 (11 items)