使用 Microsoft Visual Studio 2015 的 MSBuild 12.0 进行编译

Compiling using MSBuild 12.0 from Microsoft Visual Studio 2015

我有一个使用 MSVC 12.0 Visual Studio 2013(C++/CLI 和 C#)编译的解决方案,但只有 Visual Studio 2015(社区)。我想按预期使用 MSVC 12.0 构建项目,因为我只需要为我的目的重建解决方案的 1 个部分(共 5 个),并希望它与其他 DLL 兼容。当尝试从 MSVC 14.0 (Visual Studio 2015) 构建它时,它说:

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets(57,5): error MSB8020: The build tools for v120 (Platform Toolset = 'v120') cannot be found.

当然,我从这里安装了 2013 版 MS 构建工具(MSVC 12.0、v120):https://www.microsoft.com/en-us/download/details.aspx?id=40760 以及 Microsoft Visual C++ Redistributable 2013 软件包。

12.0 构建工具安装的正确目录是 C:\Program Files (x86)\MSBuild.0\Bin\amd64

它看起来像是解决方案的配置错误(或通常 Visual Studio),因为它正在错误的目录中寻找构建工具。有谁知道我需要在 Visual Studio 中更改/添加哪些设置才能使用 MSBuild 12.0 而不是 14.0 进行编译?我不想安装 Visual Studio 2013,因为我不将它用于任何其他用途(只是想根据需要选择在 VS 2015 中使用 VS 2013 MSBUILD)。

如果您转到 .vcxproj 的顶部,请将其更改为

<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

那你的.sln在2015年Visual Studio还能开

VisualStudioVersion = 14.0.25420.1

原因是因为编译器版本是在逐个项目的基础上指定的,并且会覆盖解决方案版本。

I'd prefer not to install Visual Studio 2013 since I don't use it for anything else (just want to have the option to use VS 2013 MSBUILD within VS 2015 as needed).

您可以从 VS2015 安装程序安装 VS2013 工具集版本,而无需安装 visual studio 2013。从 2015 安装程序,select Windows 8.1 和 Windows Phone 8.0/8.1 工具 Visual C++ 2015 常用工具:

安装完成后,您将在下方找到平台工具集:

然后您可以使用平台工具集 Visual Studio 2013(v120) 构建您的项目。

您可以参考 上的更多信息。

好的,我已经完成了这项工作,尽管是以一种迂回的方式。感谢其他回答和评论的人。免费注册 Microsoft Visual Studio Dev Essentials 订阅。 https://azure.microsoft.com/en-us/pricing/member-offers/vs-dev-essentials/ Then you can go through the menus and download Visual Studio Community 2013 by going to this link and finding it https://my.visualstudio.com/downloads。这样做之后,您可以从 Visual Studio 2015 构建 MSVC 12.0。当然,不完美,但它可以工作。我没有尝试卸载 Visual Studio 2013 以查看它是否仍然有效(Windows Phone SDK 8.1 与 2013 一起安装,如前所述,以使其在 2015 的企业版中工作)但是如果您能以某种方式保留它并删除 2013 版,我相信它可以在不安装 2013 的情况下运行...