查找 VisualStudio 各版本 msbuild 路径

使用场景

场景1

在编译项目时,例如编译自己的项目:msbuild xxx.sln

场景2

使用nuget 还原命令的时候,会使用到msbuild命令,如使用 nuget restore 命令还原项目的 NuGet 包的时候,NuGet 会尝试自动检测计算机上已经安装的 MSBuild。不过,如果你同时安装了 Visual Studio 2017 和 Visual Studio 2019,那么 NuGet 有可能找到错误版本的 MSBuild。

当我们敲下 nuget restore 命令的时候,命令行的第 2 行会输出自动检测到的 MSBuild 版本号,就像下面的输出一样:

NuGet Version: 5.0.2.5988
MSBuild auto-detection: using msbuild version ‘15.9.21.664from ‘C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin’. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.

实际上我计算机上同时安装了 Visual Studio 2017 和 Visual Studio 2019,我有两个不同版本的 MSBuild:

vs2017的版本是15.9.21.664,在 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin
vs2019的版本是16.1.76.45076,在 C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin

参考链接:https://blog.csdn.net/WPwalter/article/details/101511799

 

如何查找 msbuild 路径

方法1:

使用 where 命令查找(Linux系统中是 whereis 命令),如下:

where msbuild

如果有多个路径,都会被显示出来。

但是有个前提条件:必须是已经加到环境变量的 path 中的。

所以这个方法不适合我使用。

方法2:

通过 vswhere.exe 工具找到路径,可以解决多个版本的 vs 不知道使用哪个

"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"-latest -prerelease -products *-requires Microsoft.Component.MSBuild-find MSBuild\**\Bin\MSBuild.exe

VisualStudio 2019 企业版

C:\Program Files(x86)\Microsoft VisualStudio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe

社区版

C:\Program Files(x86)\Microsoft VisualStudio\2019\Community\MSBuild\Current\Bin\MSBuild.exe

专业版

C:\Program Files(x86)\Microsoft VisualStudio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe

我搭建了自己的博客 https://blog.lindexi.com/ 欢迎大家访问,里面有很多新的博客。

如果在博客看到有任何不懂的,欢迎交流

出处: https://blog.51cto.com/u_11283245/2955569

 

这个方式可以搜索出微软的产品,具体的还需要研究一下 vswhere.exe 命令的具体使用。

 

posted on   jack_Meng  阅读(2836)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2020-05-09 SQL Server 中 WaitFor 延时执行的用法
2020-05-09 sublime text 3 + python配置,完整搭建及常用插件安装
2020-05-09 Sublime Text 3 设置中文+禁用更新+永久激活教程(2020.2.10测试可用)
2019-05-09 收起.NET程序的dll来
2014-05-09 NET简单的一个画图程序
2014-05-09 公共的Json操作类
2014-05-09 ASP.NET 程序优化

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示

喜欢请打赏

扫描二维码打赏

支付宝打赏

主题色彩