示例脚本
msbuild
rem DataUpgrade专用脚本,请勿删除!
echo off
set "msbuildPath="
set "msbuildPath14=%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
set "msbuildPath15=%ProgramFiles(x86)%\MSBuild\15.0\Bin\MSBuild.exe"
set "msbuildPathvs17=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe"
set "msbuildPathvs19=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe"
if exist "%msbuildPath14%" set "msbuildPath=%msbuildPath14%"
if exist "%msbuildPath15%" set "msbuildPath=%msbuildPath15%"
if exist "%msbuildPathvs17%" set "msbuildPath=%msbuildPathvs17%"
if exist "%msbuildPathvs19%" set "msbuildPath=%msbuildPathvs19%"
cd /d %~dp0
set "nugetPath=Build\nuget.exe"
echo "MS编译器路径:%msbuildPath%"
::判断msbuild
if "%msbuildPath%" == "" goto nomsbuild
echo 正在编译导数工具代码...
echo "还原NuGet"
%nugetPath% restore "$(SolutionDir)src/DataUpgrade.Notification/DataUpgrade.Notification.csproj"
echo "编译"
"%msbuildPath%" "$(SolutionDir)src/DataUpgrade.Notification/DataUpgrade.Notification.csproj" /t:Rebuild /p:Configuration="Debug" /consoleloggerparameters:ErrorsOnly /nologo /m
if errorlevel 1 goto fail
echo 编译成功...
goto exit
:nomsbuild
echo 没有找到MSBUILD
pause
:exit
exit /b 0
:fail
echo 编译成失败..
exit /b 1
使用方式
将上述脚本放到 properties->Build Events 里面即可(自行修改需要目标项目位置)。