最近在看一些算法和測試一些程序,以及幫團隊測試程序,團隊使用了vs開發環境建立的sln項目文件,我使用的是公司的機器,沒有任何權限安裝程序等操做,可是又須要編譯一些程序,因此我想到了,使用MSBuild.exe進行編譯。html
若是你的機器上沒有裝有VisualStudio,那麼能夠使用MSBuild來build .sln或project。能夠不用安裝vs程序,MSBuild能夠經過安裝.NETFramework來安裝,通常的安裝路徑爲C:\Windows\Microsoft.NET\Framework。其實devenv執行build時候,後臺也是調用MSBuild來build的。算法
能夠使用msbuild /?來查看詳細的幫助;ide
今天就簡單的介紹下使用MSBuild.exe編譯程序的方法:工具
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe "c:\test\test1.sln" /property:Configuration=Debug /t:build /p:VisualStudioVersion=14.0
說明:若是你想編譯單個文件,或者是測試某段程序算法等,能夠不用考慮使用那個版本的MSBuild.exe程序。post
簡單實例: 測試
一樣注意,若是project引用了其餘的projects的時候,最好build整個.sln。 優化
參考: MSBuild入門 MSBuild入門(續) MSBuild功能介紹 ui
=================================================================================================this
參考以下:spa
背景:VS很好很強大,但太費系統資源了,尤爲是在虛擬機在裏面裝VS的時候更是如此。有時用vi編輯了源代碼後,不想開VS IDE編譯,但每次打開VS命令行,再切換到工程所在目錄,而後手動敲命令太麻煩了。因而產生了集成集成VS命令行編譯到.sln文件右鍵菜單的想法。
直接上圖:
本版本支持 Win10 + VS2015
出處:http://www.cnblogs.com/crazybird/p/5103906.html
======================================================
臨時手寫了個,能夠參考吧
@ECHO OFF set ms="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe" cls %ms% /version color 0c ECHO. ECHO. echo Do you use this version of MSBuild.exe to compile the current program? Close this window if you don't compile. pause color GOTO End IF /I "%1"=="Debug" GOTO BuildDebug IF /I "%1"=="Release" GOTO BuildRelease IF /I "%1"=="All" GOTO BuildAll IF /I "%1"=="Minimal" GOTO BuildMinimal :ER ECHO. ECHO Raspkate Command-Line Build Tool v1.0 ECHO. ECHO Usage: ECHO build.bat Debug ECHO Builds the Raspkate with Debug configuration. ECHO. ECHO build.bat Release ECHO Builds the Raspkate with Release configuration. ECHO. GOTO End :BuildDebug %ms% /p:Configuration="Debug";TargetFrameworkVersion="v4.5.2" Raspkate.sln GOTO End :BuildRelease %ms% /p:Configuration="Release";TargetFrameworkVersion="v4.5.2" Raspkate.sln GOTO End :BuildAll %ms% /p:Configuration="All";TargetFrameworkVersion="v4.5.2" Raspkate.sln GOTO End :BuildMinimal %ms% /p:Configuration="Minimal";TargetFrameworkVersion="v4.5.2" Raspkate.sln GOTO End :End @ECHO ON
優化版本
@ECHO OFF :: 建議使用開發時使用VS的版本對應的MSBuild.exe程序 set ms="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe" cls %ms% /version ECHO, IF /I "%1"=="Debug" GOTO BuildDebug IF /I "%1"=="Release" GOTO BuildRelease IF /I "%1"=="All" GOTO BuildAll IF /I "%1"=="Minimal" GOTO BuildMinimal color 0c ECHO, ECHO, echo Do you use this version of MSBuild.exe to compile the current program? Close this window if you don't compile. echo,&&echo 1:Building projects with Debug models echo,&&echo 2:Building projects with Release models echo,&&echo 3:Building projects with Minimal models echo,&&echo 4:Building projects with All models echo; set /p buildType=Please enter number of your build mode : ::pause color ::GOTO End IF /I "%buildType%"=="1" GOTO BuildDebug IF /I "%buildType%"=="2" GOTO BuildRelease IF /I "%buildType%"=="3" GOTO BuildMinimal IF /I "%buildType%"=="4" GOTO BuildAll :ER ECHO, ECHO MSBuild.exe Command-Line Build Tool v1.0 ECHO, ECHO Usage: ECHO build.bat Debug ECHO Builds the Solution or Project with Debug configuration. ECHO, ECHO build.bat Release ECHO Builds the Solution or Project with Release configuration. ECHO, GOTO End :BuildDebug echo you chose Debug build %ms% /p:Configuration="Debug" Car.sln echo you chose Debug build completed GOTO End :BuildRelease echo you chose Release build %ms% /p:Configuration="Release" Car.sln echo you chose Release build completed GOTO End :BuildAll echo you chose All build %ms% /p:Configuration="All" Car.sln echo you chose All build completed GOTO End :BuildMinimal echo you chose Minimal build %ms% /p:Configuration="Minimal" Car.sln echo you chose Minimal build completed GOTO End :End pause @ECHO ON