在命令行覆盖目标框架 [英] Override target framework from command line

查看:179
本文介绍了在命令行覆盖目标框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建立使用的MSBuild (.csproj的)命令行从一个 C#项目,并希望到目标.NET2 0.0运行时。



我看到项目XML文件 2标签感兴趣

 <项目ToolsVersion =4.0... 

 < TargetFrameworkVersion>&2.0 LT; / TargetFrameworkVersion> 



我在想,如果




  • 可以ToolsVersion 4.0生产兼容代码.Net2.0运行?

  • 我可以覆盖从通过命令行项目文件中的目标框架标记(是否 / ToolsVersion 命令行开关实现这一目标?



我特别想通过命令行来实现这一目标而不是修改项目文件。



目前我做这样的事情。

 的MSBuild myproj.csproj / p:配置=释放


解决方案

您需要的命令行参数进行的MSBuild,使这项工作:

  msbuild.exe MyProj.proj / p:TargetFrameworkVersion = V2 0.0;配置=释放/tv:3.5 

therfore藏汉覆盖在凸出文件中的值作为ToolsVersion。



要找出MSBuild的版本默认使用哪个,启动Visual Studio命令提示符(在开始菜单中>微软的Visual Studio 2010> Visual Studio工具)和类型的MSBuild。
输出的第一行会牵你的BuidEngineversion:




微软(R)生成引擎版本4.0.30319.1




从MSDN文档:




MSBuild的使用工具集的任务,目标和工具,建立一个
应用。一般情况下,的MSBuild工具集包括一个
microsoft.common.tasks文件,microsoft.common.targets文件,
编译器,如CSC.EXE和VBC.EXE。大多数工具集可以用来
编译应用到.NET框架
的多个版本和一个以上的系统平台




您还可以检查环境瓦尔的安装框架版本:
集合F 从Visual Studio命令提示符给我这样的结果




Framework35Version = V3.5结果
FrameworkDir = C:\Windows\Microsoft.NET\Framework \结果
FrameworkDIR32 = C:\Windows\Microsoft.NET\Framework\结果
FrameworkVersion = v4.0.30319结果
FrameworkVersion32 = v4.0.30319




工具集解释结果
ToolSetVersion


I want to build a c# project(.csproj) from commandline using msbuild and want to target .Net2.0 runtime.

I see that the project xml file has 2 tags of interest

<Project ToolsVersion="4.0" ... 

and

<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>

I was wondering if

  • Can ToolsVersion 4.0 produce compatible code for .Net2.0 runtime?
  • Can I override the target framework tag from the project file via the command line (does the /ToolsVersion command line switch achieve this?

I specifically want to achieve this via command line and not modify the project file.

Currently I am doing something like this

msbuild myproj.csproj /p:Configuration=Release

解决方案

You need the commandline arguments for msbuild to make that work:

msbuild.exe MyProj.proj /p:TargetFrameworkVersion=v2.0;Configuration=Release /tv:3.5

therfore overriding the value in the proj file aswell as the ToolsVersion.

To find out which msbuild version default is used, start a Visual Studio Command prompt ( found in the Start menu > Microsoft Visual studio 2010 > Visual Studio Tools) and type msbuild. The first line of the output will hold your BuidEngineversion:

Microsoft (R) Build Engine Version 4.0.30319.1

From the msdn doc:

MSBuild uses a tool set of tasks, targets, and tools to build an application. Typically, a MSBuild tool set includes a microsoft.common.tasks file, a microsoft.common.targets file, and compilers such as csc.exe and vbc.exe. Most tool sets can be used to compile applications to more than one version of the .NET Framework and more than one system platform

You could also check the Environment vars for a version of the framework installed: set F from the Visual Studio Command prompt gives me this result:

Framework35Version=v3.5
FrameworkDir=c:\Windows\Microsoft.NET\Framework\
FrameworkDIR32=c:\Windows\Microsoft.NET\Framework\
FrameworkVersion=v4.0.30319
FrameworkVersion32=v4.0.30319

ToolSet Explanation
ToolSetVersion

这篇关于在命令行覆盖目标框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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