VS2017中msbuild的不同路径 [英] Different Paths To msbuild in VS2017

查看:807
本文介绍了VS2017中msbuild的不同路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

操作系统:Microsoft Windows [Version 10.0.14393]

VS版本:2017 Community

当我运行vswhere.exe时,基于官方vswhere 文档我可以构建msbuild的路径,这似乎可行:

C:\Users\user\Desktop>"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
Visual Studio Locator version 1.0.62 [query version 1.10.80.60812]
Copyright (C) Microsoft Corporation. All rights reserved.
[...]
installationPath: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community
[...]
C:\Users\user\Desktop>"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe"
Microsoft (R)-Buildmodul, Version 15.1.1012.6693

如果我启动"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsMSBuildCmd.bat"中的开发人员命令提示符,则会得到以下结果:

C:\Users\user>"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsMSBuildCmd.bat"
**********************************************************************
** Visual Studio 2017 MSBuild Command Prompt
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
C:\Users\user>where msbuild
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe


  1. 为什么以及启动开发人员命令提示符后返回的第二条路径是什么
  2. 我总是使用第一个路径("C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe")调用msbuild来构建C/C ++/VC ++项目.这在某种程度上是错误的吗?

解决方案

VS 2017切换到msbuild的本地副本,如果使用VS 2015命令提示符,则会看到不同的全局路径.

where命令列出了它在PATH上找到的所有匹配的可执行文件,但是当您运行msbuild命令时,命令提示符仅使用第一个文件.

您看到的第二个msbuild.exe是.NET Framework的一部分-这是MSBuild的版本,已集成到该版本中并作为.NET Framework的一部分提供.与最新版本的Visual Studio安装的版本相比,该版本较旧.但是出于兼容性原因,它可能会继续包含在.NET Framework中.它甚至能够构建许多项目,然后再使用VS安装的目标和任务-仅需要对MSBuild本身进行更改的项目格式更改将是不兼容的(例如用于.NET Core项目的新项目格式)./p>

您应始终使用VS 2017版本的msbuild.exe始终获得与Visual Studio一致的构建结果.

OS: Microsoft Windows [Version 10.0.14393]

VS-Version: 2017 Community

When I run vswhere.exe I get the following back and based on on the official vswhere documentation I can build the path to msbuild and this seems to work:

C:\Users\user\Desktop>"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
Visual Studio Locator version 1.0.62 [query version 1.10.80.60812]
Copyright (C) Microsoft Corporation. All rights reserved.
[...]
installationPath: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community
[...]
C:\Users\user\Desktop>"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe"
Microsoft (R)-Buildmodul, Version 15.1.1012.6693

If I start the developer command prompt located in "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsMSBuildCmd.bat" I get the following result:

C:\Users\user>"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsMSBuildCmd.bat"
**********************************************************************
** Visual Studio 2017 MSBuild Command Prompt
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
C:\Users\user>where msbuild
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe


  1. Why and what is the second path returned after starting the developer command prompt
  2. I always use the first path ("C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe") to call msbuild for building C/C++/VC++ Projects. Is this in someway wrong?

解决方案

VS 2017 switched to local copies of msbuild, if you used a VS 2015 command prompt, you would see a different global path.

The where command lists all the matching executable files that it finds on the PATH, but only the first one will be used by the command prompt when you run an msbuild command.

The second msbuild.exe you see is part of the .NET Framework - this is the version of MSBuild that was integrated into and shipped as part of the .NET Framework. This version is old compared to the ones installed by recent versions of Visual Studio. But it will likely be continued to be included in .NET Framework for compatibility reasons. It is even able to build a lot of projects that will then use the targets and tasks installed by VS - only project format changes that required changes to MSBuild itself will be incompatible (like the new project format used for .NET Core projects).

You should always use the VS 2017 version of msbuild.exe to always get build results consistent with visual studio.

这篇关于VS2017中msbuild的不同路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆