visual-studio 如何获取 VS 解决方案的 cmd 行构建命令?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/280559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get cmd line build command for VS solution?
提问by JohnIdol
This is probably easy but I am getting stuck: when I build a solution in Visual Studio - how do extract the exact cmd line for the current build command in order to be able to do the same build from VisualStudio console?
这可能很容易,但我遇到了问题:当我在 Visual Studio 中构建解决方案时 - 如何为当前构建命令提取确切的 cmd 行,以便能够从 VisualStudio 控制台执行相同的构建?
In the output window I can see the single projects in the solution build commands but not the one for the whole solution.
在输出窗口中,我可以看到解决方案构建命令中的单个项目,但不是整个解决方案的项目。
I am on VS2005.
我在 VS2005 上。
Any help would be appreciated
任何帮助,将不胜感激
采纳答案by kenny
In addition to what @JohnIdol says correctly, I've found that you need to setup a number VS environment variables. I don't have the name of the batch file in front of me, but you can modify or 'I think' use it. It is in VS program files tree somewhere. Also, as I remember you don't want to be in a standard shell but a .NET setup shell for some paths and such. I'll add details later when I'm at a Windows PC with VS.
除了@JohnIdol 所说的正确之外,我发现您需要设置一些 VS 环境变量。我面前没有批处理文件的名称,但您可以修改或“我认为”使用它。它位于 VS 程序文件树中的某处。另外,我记得你不想在标准外壳中,而是在一些路径等的 .NET 设置外壳中。稍后我会在装有 VS 的 Windows PC 上添加详细信息。
EDIT: The batch file mentioned is a shortcut in ProgFiles menu. Here is the details of its properties.
编辑:提到的批处理文件是 ProgFiles 菜单中的快捷方式。这是其属性的详细信息。
%comspec% /k ""C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat""x86"
Here is my batch file, using MSBuild to call the solution.
这是我的批处理文件,使用 MSBuild 调用解决方案。
@echo off
:: setup VS2005 command line build environment
set VSINSTALLDIR=C:\Program Files\Microsoft Visual Studio 8
set VCINSTALLDIR=C:\Program Files\Microsoft Visual Studio 8\VC
set FrameworkDir=C:\WINDOWS\Microsoft.NET\Framework
set FrameworkVersion=v2.0.50727
set FrameworkSDKDir=C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0
set DevEnvDir=C:\Program Files\Microsoft Visual Studio 8\Common7\IDE
set PATH=C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;C:\Program Files\Microsoft Visual Studio 8\VC\BIN;C:\Program Files\Microsoft Visual Studio 8\Com
mon7\Tools;C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\bin;C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\bin;C:\Program Files\Microsoft
Visual Studio 8\SDK\v2.0\bin;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 8\VC\VCPackages;%PATH%
set INCLUDE=C:\Program Files\Microsoft Visual Studio 8\VC\ATLMFC\INCLUDE;C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE;C:\Program Files\Microsoft Visual
Studio 8\VC\PlatformSDK\include;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\include;%INCLUDE%
set LIB=C:\Program Files\Microsoft Visual Studio 8\VC\ATLMFC\LIB;C:\Program Files\Microsoft Visual Studio 8\VC\LIB;C:\Program Files\Microsoft Visual Studio 8\VC
\PlatformSDK\lib;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\lib;%LIB%
set LIBPATH=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 8\VC\ATLMFC\LIB
echo %0 %*
echo %0 %* >> %MrB-LOG%
cd
if not ""=="%~dp1" pushd %~dp1
cd
if exist %~nx1 (
echo VS2005 build of '%~nx1'.
echo VS2005 build of '%~nx1'. >> %MrB-LOG%
set MrB-BUILDLOG=%MrB-BASE%\%MrB-WORK%.%MrB-NICEDATE%.%MrB-NICETIME%.build-errors.log
msbuild.exe %~nx1 /t:Rebuild /p:Configuration=Release > %MrB-BUILDLOG%
findstr /r /c:"[1-9][0-9]* Error(s)" %MrB-BUILDLOG%
if not errorlevel 1 (
echo ERROR: sending notification email for build errors in '%~nx1'.
echo ERROR: sending notification email for build errors in '%~nx1'. >> %MrB-LOG%
call mrb-email "Mr Build isn't happy about build errors in '%~nx1'" %MrB-BUILDLOG%
) else (
findstr /r /c:"[1-9][0-9]* Warning(s)" %MrB-BUILDLOG%
if not errorlevel 1 (
echo ERROR: sending notification email for build warnings in '%~nx1'.
echo ERROR: sending notification email for build warnings in '%~nx1'. >> %MrB-LOG%
call mrb-email "Mr Build isn't happy about build warnings in '%~nx1'" %MrB-BUILDLOG%
) else (
echo Successful build of '%~nx1'.
echo Successful build of '%~nx1'. >> %MrB-LOG%
)
)
) else (
echo ERROR '%1' doesn't exist.
echo ERROR '%1' doesn't exist. >> %MrB-LOG%
)
popd
回答by icelava
Navigate to your Programs menu > Microsoft Visual Studio 2005 > Visual Studio Tools > Visual Studio 2005 Command Prompt.
导航到您的程序菜单 > Microsoft Visual Studio 2005 > Visual Studio 工具 > Visual Studio 2005 命令提示符。
this command prompt has all the necessary .NET environment variables set for the the command line session. You can change directory to your solution directory (e.g. c:\projects\mySolution) and run
此命令提示符为命令行会话设置了所有必需的 .NET 环境变量。您可以将目录更改为您的解决方案目录(例如 c:\projects\mySolution)并运行
Msbuild.exe mySolution.sln
You can see the various options available using msbuild /?
您可以使用msbuild /?
Msbuild is located at C:\Windows\Microsoft.NET\Framework\v2.0.50727
Msbuild 位于 C:\Windows\Microsoft.NET\Framework\v2.0.50727
On top of msbuild /? quick-option check, you may reference the MSBuild Command Line Referencepage for more explanations on its usage. And how to build specific targets in solutions.
在 msbuild /? 快速选项检查,您可以参考MSBuild 命令行参考页面以获取有关其用法的更多说明。以及如何在解决方案中构建特定目标。
回答by kenny
For VS .NET 2003 you can use devenv.exe to build the solution/project from command line.
对于 VS .NET 2003,您可以使用 devenv.exe 从命令行构建解决方案/项目。
devenv solutionfile.sln /build solutionconfig
E.g. usage in batch file:
例如在批处理文件中的用法:
call "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\vsvars32.bat"
devenv Tools.sln /build "Release"
回答by David Sykes
If you want to see the exact command line as provided by VS (rather than work it out) then you could try replacing the MSBuild.exe with your own console app that prints out all the parameters to a file.
如果您想查看 VS 提供的确切命令行(而不是解决它),那么您可以尝试将 MSBuild.exe 替换为您自己的控制台应用程序,该应用程序将所有参数打印到文件中。
You could also write out all the environment variables supplied to check which ones VS provides in the background.
您还可以写出提供的所有环境变量,以检查 VS 在后台提供的环境变量。
回答by crash
I just want to thank the Bejoy on the example. I had big problems with solution rebuild on setup pre build event because they removed most of the macros and this helped me a lot.
我只想感谢 Bejoy 上的例子。我在 setup pre build 事件中重建解决方案时遇到了大问题,因为他们删除了大部分宏,这对我有很大帮助。
Here is my solution based on Bejoy's (considering that .bat file is located in setup root folder which is part of solution):
这是我基于 Bejoy 的解决方案(考虑到 .bat 文件位于 setup 根文件夹中,这是解决方案的一部分):
call "%VS100COMNTOOLS%\vsvars32.bat"
devenv "%CD%\..\soulutionfile.sln" /build "Release"
回答by Mendelt
You can start msbuild from the command line. msbuild understands .sln (solution) files. You can specify the .sln file and the build configuration (debug, release etc.) from the command line.
您可以从命令行启动 msbuild。msbuild 理解 .sln(解决方案)文件。您可以从命令行指定 .sln 文件和构建配置(调试、发布等)。
http://msdn.microsoft.com/en-us/library/ms164311.aspx
Here is the documentation on what you can do with msbuild. MSBuild.exe is installed with the .net framework, not with visual studio. You can find it in c:\windows\microsoft.net\framework\v3.5 (or v2.0.50727)
http://msdn.microsoft.com/en-us/library/ms164311.aspx
以下是有关 msbuild 可以做什么的文档。MSBuild.exe 随 .net 框架一起安装,而不是随 Visual Studio 一起安装。您可以在 c:\windows\microsoft.net\framework\v3.5(或 v2.0.50727)中找到它
I searched a bit and found that you can also do a command line build with visual studio using devenv.exe /build, more info here:
http://msdn.microsoft.com/en-us/library/xee0c8y7(VS.80).aspx
我搜索了一下,发现您还可以使用 devenv.exe /build 使用 Visual Studio 进行命令行构建,更多信息请点击此处:http:
//msdn.microsoft.com/en-us/library/xee0c8y7(VS.80 ).aspx

