在 Windows 中,使用脚本中自动查找 MSBuild 的位置

新的 .NET 项目可以直接使用 dotnet 命令,但旧的 .NET Framework 项目仍然需要 MSBuild 进行生成。

为了方便在不同环境下的自动编译

可以通过 Visual Studio Installer 的命令参数进行查找:

  • PowerShell: &"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe
  • CMD: "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe

参考:

https://learn.microsoft.com/zh-cn/visualstudio/msbuild/find-and-use-msbuild-versions?view=vs-2022

https://stackoverflow.com/questions/328017/path-to-msbuild

posted @ 2024-09-06 09:52  不是豆豆  阅读(142)  评论(0)    收藏  举报
友情链接:迷途