首先,在Bitbucket 构建配置中输设置 MSBuild 路径,指向你的 MSBuild-Binaries 文件夹。
image: mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019
pipelines:
branches:
master:
- step:
name: Build .NET Solution
script:
- "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\MSBuild\\Current\\Bin\\MSBuild.exe" /t:restore /t:build /p:Configuration=Release MySolution.sln
如果你使用的是 MSBuild 预览版,那么你需要在命令中添加一些额外的参数,以保证编译的正常运行。例如,以下代码可以使用 MSBuld 的预览版进行编译:
script:
- "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Preview\\MSBuild\\Current\\Bin\\MSBuild.exe" /t:restore /t:build /p:Configuration=Release MySolution.sln
需要注意的是,这里使用的是 MSBuild 预览版的文件路径,以及额外的参数 /t:restore /t:build
。