标签归档:visual-studio-2008

如何从命令行编译Visual Studio项目?

问题:如何从命令行编译Visual Studio项目?

我正在为使用MonotoneCMake,Visual Studio Express 2008和自定义测试的大型C ++解决方案编写结帐,构建,分发,测试和提交周期的脚本。

所有其他部分似乎都非常简单明了,但是我不明白如何在没有GUI的情况下编译Visual Studio解决方案。

该脚本是用Python编写的,但是给出的答案允许我仅调用os.system。

I’m scripting the checkout, build, distribution, test, and commit cycle for a large C++ solution that is using Monotone, CMake, Visual Studio Express 2008, and custom tests.

All of the other parts seem pretty straight-forward, but I don’t see how to compile the Visual Studio solution without getting the GUI.

The script is written in Python, but an answer that would allow me to just make a call to: os.system would do.


回答 0

我知道有两种方法可以做到。

方法1
第一种方法(我更喜欢)是使用msbuild

msbuild project.sln /Flags...

方法2
您还可以运行:

vcexpress project.sln /build /Flags...

vcexpress选项立即返回,并且不打印任何输出。我想这可能就是您想要的脚本。

请注意,DevEnv并未随Visual Studio Express 2008一起分发(我花了很多时间试图弄清第一次遇到类似问题的时间)。

因此,最终结果可能是:

os.system("msbuild project.sln /p:Configuration=Debug")

您还需要确保您的环境变量正确,因为默认情况下,系统路径上不包含msbuild和vcexpress。启动Visual Studio构建环境并从那里运行脚本,或者修改Python中的路径(使用os.putenv)。

I know of two ways to do it.

Method 1
The first method (which I prefer) is to use msbuild:

msbuild project.sln /Flags...

Method 2
You can also run:

vcexpress project.sln /build /Flags...

The vcexpress option returns immediately and does not print any output. I suppose that might be what you want for a script.

Note that DevEnv is not distributed with Visual Studio Express 2008 (I spent a lot of time trying to figure that out when I first had a similar issue).

So, the end result might be:

os.system("msbuild project.sln /p:Configuration=Debug")

You’ll also want to make sure your environment variables are correct, as msbuild and vcexpress are not by default on the system path. Either start the Visual Studio build environment and run your script from there, or modify the paths in Python (with os.putenv).


回答 1

MSBuild通常可以正常工作,但是我之前遇到过困难。你可能有更好的运气

devenv YourSolution.sln /Build 

MSBuild usually works, but I’ve run into difficulties before. You may have better luck with

devenv YourSolution.sln /Build 

回答 2

老实说,我必须加2美分。

您可以使用msbuild.exe来完成msbuild.exe的版本很多 。

C:\ Windows \ Microsoft.NET \ Framework64 \ v2.0.50727 \ msbuild.exe C:\ Windows \ Microsoft.NET \ Framework64 \ v3.5 \ msbuild.exe C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ msbuild.exe
C:\ Windows \ Microsoft.NET \ Framework \ v2.0.50727 \ msbuild.exe C:\ Windows \ Microsoft.NET \ Framework \ v3.5 \ msbuild.exe C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ msbuild.exe

使用您需要的版本。基本上,您必须使用最后一个。

C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ msbuild.exe

那么怎么做。

  1. 运行命令窗口

  2. 输入msbuild.exe的路径

C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ msbuild.exe

  1. 输入项目解决方案的路径,例如

“ C:\ Users \ Clark.Kent \ Documents \ visual studio 2012 \ Projects \ WpfApplication1 \ WpfApplication1.sln”

  1. 在解决方案路径后添加所需的任何标志。

  2. ENTER

请注意,您可以获得有关所有可能标记的帮助,例如

C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ msbuild.exe / help

To be honest I have to add my 2 cents.

You can do it with msbuild.exe. There are many version of the msbuild.exe.

C:\Windows\Microsoft.NET\Framework64\v2.0.50727\msbuild.exe C:\Windows\Microsoft.NET\Framework64\v3.5\msbuild.exe C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe
C:\Windows\Microsoft.NET\Framework\v2.0.50727\msbuild.exe C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe

Use version you need. Basically you have to use the last one.

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe

So how to do it.

  1. Run the COMMAND window

  2. Input the path to msbuild.exe

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe

  1. Input the path to the project solution like

“C:\Users\Clark.Kent\Documents\visual studio 2012\Projects\WpfApplication1\WpfApplication1.sln”

  1. Add any flags you need after the solution path.

  2. Press ENTER

Note you can get help about all possible flags like

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe /help


回答 3

使用msbuild其他人指出的方法对我有用,但我需要做的不止于此。首先,msbuild需要访问编译器。这可以通过运行以下命令来完成:

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"

然后msbuild不在我的$ PATH中,所以我不得不通过它的显式路径运行它:

"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" myproj.sln

最后,我的项目使用了诸如的一些变量$(VisualStudioDir)。看来这些没有被设置,msbuild所以我不得不通过/property选项手动设置它们:

"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" /property:VisualStudioDir="C:\Users\Administrator\Documents\Visual Studio 2013" myproj.sln

那行最终使我能够编译我的项目。

奖励:命令行工具使用30天后似乎不需要注册,就像基于GUI的“免费” Visual Studio Community版本一样。有了Microsoft注册要求,该版本几乎是免费的。如果有的话免费在Facebook上…

Using msbuild as pointed out by others worked for me but I needed to do a bit more than just that. First of all, msbuild needs to have access to the compiler. This can be done by running:

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"

Then msbuild was not in my $PATH so I had to run it via its explicit path:

"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" myproj.sln

Lastly, my project was making use of some variables like $(VisualStudioDir). It seems those do not get set by msbuild so I had to set them manually via the /property option:

"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" /property:VisualStudioDir="C:\Users\Administrator\Documents\Visual Studio 2013" myproj.sln

That line then finally allowed me to compile my project.

Bonus: it seems that the command line tools do not require a registration after 30 days of using them like the “free” GUI-based Visual Studio Community edition does. With the Microsoft registration requirement in place, that version is hardly free. Free-as-in-facebook if anything…


回答 4

MSBuild是您的朋友。

msbuild "C:\path to solution\project.sln"

MSBuild is your friend.

msbuild "C:\path to solution\project.sln"

回答 5

DEVENV在许多情况下都能很好地工作,但是在WIXPROJ上构建我的WIX安装程序时,我得到的只是Out日志中的“ CATASTROPHIC”错误。

这有效:MSBUILD /Path/PROJECT.WIXPROJ / t:Build / p:Configuration =发布

DEVENV works well in many cases, but on a WIXPROJ to build my WIX installer, all I got is “CATASTROPHIC” error in the Out log.

This works: MSBUILD /Path/PROJECT.WIXPROJ /t:Build /p:Configuration=Release