1、首先在服務器上安裝好 Git 工具,並加入環境變量 Path 中
2、到 https://www.nuget.org/downloads 下載 nuget.exe,放到任意文件夾,並加入環境變量 Path 中
3、到 https://www.microsoft.com/zh-CN/download/details.aspx?id=48159 下載 BuildTools_Full.exe ,然後雙擊 exe 默認安裝,安裝後如下:
把路徑:C:\Program Files (x86)\MSBuild\14.0\Bin 加入到環境變量 Paht 中
4、從你本地安裝有 Visual Studio 2015/2017 的電腦中複製如下文件夾:
複製到服務器相同的文件目錄下
5、用 git 把代碼下載下來,(注意 git 使用自動保存賬號密碼的方式自行百度設置 ):
新建 MSBuild.cmd 文件,內容如下:
@echo off
git pull
cd src
nuget restore MSBuildTest.sln
cd MSBuildTest.Web
MSBuild MSBuildTest.Web.csproj /t:ResolveReferences;Compile /t:_CopyWebApplication /p:Configuration=Release /p:WebProjectOutputDir=..\..\PublishOutput /p:OutputPath=..\..\PublishOutput\bin
pause
cmd 命令大致意思如下:
git pull 拉取最新代碼,
cd src 目錄(.sln 所在目錄),
nuget restore xxx.sln 下載還原最新的package,
cd xxx.web 目錄(網站所在目錄)
MSBuild xxxxx.web.csproj 構建發佈命令,發佈到目錄:..\..\PublishOutput 下
6、iis 中部署一個網站,功能用於完成GIT 提交觸發,執行 MSBuild.cmd , 未完待續。。。