如何通过批处理文件使用MsBuild和VS2017编译器构建C#,C ++,C解决方案? [英] How to build C#, C++ , C Solutions using MsBuild and VS2017 compiler via Batch File?

查看:514
本文介绍了如何通过批处理文件使用MsBuild和VS2017编译器构建C#,C ++,C解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MsBuild在批处理文件中构建解决方案,如下所示:

I am building my solutions using MsBuild in a batch file as follows:

@echo off
set msBuildExe="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe"
set solutionsFile="C:\TestProject\mySln.sln"
rem Build the solutions:  
%msBuildExe% /t:Build /p:Configuration=Release /p:Platform=x64 %solutionsFile%  

问题是我安装了Visual Studio的多个版本,并且我想指出MsBuild.exe以使用VS2017的编译器.

Problem is that I have Multiple Versions of Visual Studio installed and I want to point MsBuild.exe to use the compiler of VS2017.

我该怎么做?

推荐答案

在这里您需要两件分开的事情:msbuild(用于驱动构建过程)和编译器/链接器/...以执行实际的构建阶段.它们实际上是正交的(从理论上讲,实际上并不确定它能走多远):VS2017附带的msbuild可用于使用VS2013中的编译器/链接器来构建项目,只要为其设置了环境即可.因此,您真正需要的是最后一件事:您可能不在乎确切使用哪个版本的msbuild,而是想要使用正确的C ++/C#工具集.

You need two seperate things here: msbuild, to drive the build process, and the compiler/linker/... to perform the actual build phases. These are actually orthogonal (theoretically, not sure how far it goes in practice): msbuild which comes with VS2017 can be used to build a project using the compiler/linker from VS2013, as long as the environment is setup for those. So what you really need here is that last thing: you probably don't care what version of msbuild is used exactly, you want the correct C++/C# toolsets used.

执行此操作的典型方法是运行每个VS版本随附的.bat文件,可从开始"菜单中以"

The canonical way to do that is to run the .bat files supplied with each version of VS, accessible from the start menu as 'Developer Command Prompt'. That will also setup the path to msbuild so you don't need to hardocde that. (note these batchfiles also have arguments allowing to select different versions of toolsets etc but that's out of scope for this question)

VS2017的示例,没有硬路径,因此可以在计算机和企业/社区/...之间重复使用:

Example for VS2017, no hardocded paths so should be reusable accross machines and enterprise/community/...:

@echo off
call "%VS150COMNTOOLS\Tools\VsDevCmd.bat"
set solutionsFile="C:\TestProject\mySln.sln"
msbuild /t:Build /p:Configuration=Release /p:Platform=x64 %solutionsFile%  

这篇关于如何通过批处理文件使用MsBuild和VS2017编译器构建C#,C ++,C解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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