最近在看一些算法和测试一些程序,以及帮团队测试程序,团队使用了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