如何将在Visual Studio IDE中进行的构建转换为可从命令行运行的脚本?
如何将在Visual Studio IDE中进行的构建转换为可从命令行运行的脚本?
使用VS2008,您可以做到这一点:
devenv solution.sln /build configuration
\Windows\Microsoft.NET\Framework\[YOUR .NET VERSION]\msbuild.exe
有很多命令行参数,但最简单的是:
msbuild.exe yoursln.sln
D:
cd "D:\MySoln"
if "%1" == "" goto all
if %1 == x86 goto x86
if %1 == x64 goto x64
:x86
%comspec% /k ""C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86 < crosscompilex86.bat
goto eof
:x64
%comspec% /k ""C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86_amd64 < crosscompilex64.bat
goto eof
:all
%comspec% /k ""C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86 < crosscompilex86.bat
if %ERRORLEVEL% NEQ 0 goto eof
%comspec% /k ""C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86_amd64 < crosscompilex64.bat
goto eof
:eof
pause
devenv MySoln.sln /clean "Release|x86"
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
devenv MySoln.sln /rebuild "Release|x86"
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
devenv MySoln.sln /clean "Release|x64"
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
devenv MySoln.sln /rebuild "Release|x64"
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
最简单的方法:进入包含解决方案或项目文件的目录,并运行msbuild
(假设你有Visual Studio 2005或更新版本)。
更灵活的方法:
以下是我的批处理文件,使用msbuild来进行VS2010的调试配置:
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"
iTegra.Web.sln /p:Configuration=Debug /clp:Summary /nologo
我不得不为 Visual Studio 2003 中的 C++ 项目做这个,所以我不知道这对 Visual Studio 的后续版本有多么相关:
在生成可执行文件的目录中,将会有一个 BuildLog.htm
文件。在浏览器中打开该文件,然后对于每个部分,例如:
Creating temporary file "c:\some\path\RSP00003C.rsp" with contents
[
/D "WIN32" /D "_WINDOWS" /D "STRICT" /D "NDEBUG" ..... (lots of other switches)
.\Project.cpp
.\Another.cpp
.\AndAnother.cpp
".\And Yet Another.cpp"
]
Creating command line "cl.exe @c:\some\path\RSP00003C.rsp /nologo"
cl.exe @autobuild01.rsp /nologo