命令行编译VisualStudio

  1. call "D:\Program Files\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"  
  2. msbuild "WPEX.vcxproj" /p:Configuration=Debug /m  

使用devenv/MSBuild在命令行编译单个project

一 使用devenv来build单个project

devenv是VisualStudio的可执行程序,一般安装在“C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE”下。用来在命令行或GUI方式运行VisualStudio。其中devenv.com是命令行程序,devenv.exe是GUI的程序。默认地当你调用devenv的时候其实是启动devenv.com,除非你显示地调用devenv.exe才会启动GUI的VisualStudio。


使用devenv来build一个.sln的实例:
devenv d:\Build\MyProject\Src\MyProject.sln /Build "Release|Win32"  

 

使用devenv来build一个.sln中的某个的实例:
devenv.exe d:\Build\MyProject\Src\NyProject.sln /build "Release|Win32" /Project MyProject1 
注意:通常地.sln中的多个Projects间有依赖关系,所以虽然你只是build一个.sln中的某个Project,但是还是需要指定Project所在.sln,然后通过/Project来指定Project的名字。
 

如果只是单个的Project,没有引用其他的projects,这个时候可以不指定.sln,直接build Project,如下实例:

devenv d:\Build\MyProject\Src\MyProject.vcxproj /Build "Release|Win32"

注意此时实际上devenv做如下事:

此时devenv将在此project文件的父目录中查找与Project相同名字的.sln;
如果没有找到的话,然后查找其他的引用了此Project的.sln;
如果还是没有找到的话会创建临时的不保存的与Project同名的.sln。

 

二 devenv的更多帮助 

可以使用devenv /?来查看详细的帮助。
.sln或project的路径有空格时,需要对路径加"";
多个/开关间使用空格隔开;
devenv不支持通配符或正则表达式语法;

 

三 MSBuild

如果你的机器上没有装有VisualStudio,那么可以使用MSBuild来build .sln或project。MSBuild可以通过安装.NETFramework来安装,一般的安装路径为C:\Windows\Microsoft.NET\Framework。其实devenv执行build时候,后台也是调用MSBuild来build的。

 

可以使用msbuild /?来查看详细的帮助;

 

简单实例如下: 

MSBuild MyApp.sln /t:Rebuild /p:Configuration=Release
MSBuild MyApp.csproj /t:Clean
                     /p:Configuration=Debug /p:Platform=x86;TargetFrameworkVersion=v3.5

 

同样注意,如果project引用了其他的projects的时候,最好build整个.sln。 


Visual C++ Team Blog

C++ tutorials, C and C++ news, and information about the C++ IDE Visual Studio from the Microsoft C++ team.

Visual C++ Team Blog

VCBuild vs. C++ MSBuild on the Command Line

January 11, 2010 by  Visual CPP Team  //  12 Comments
  • Share
  • 0
  • 0

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 .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

MSBuild.exe

Build Solution

VCBuild.exe

MSBuild.exe

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:

/p:Platform=

Configuration

/p: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: /p:SelectedFiles=”

 

/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 – https://channel9.msdn.com/posts/Charles/Bogdan-Mihalcea-The-New-VC-ProjectBuild-system-MSBuild-for-C/

Felix Huang

VC Project & Build Team

你可能感兴趣的:(windows运行不起来,__attribute__,((constructor)),windows线程,Visual,Studio,linux)