MSBuild,条件NET运行时 [英] MSBuild, conditional NET runtime

查看:78
本文介绍了MSBuild,条件NET运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一套工具需要根据MsBuild条件在NET 3.5或NET 4.0上进行部署.目前,我们想更改这些实用程序的项目文件以解决此问题. 我们知道我们可以做这样的事情:

I have a set of tools that need to be deployed on NET 3.5 or NET 4.0 depending on an MsBuild condition. At the moment we would like to change the project file of those utilities to handle this. We are aware that we can do something like this:

<TargetFrameworkVersion Condition="">v3.5</TargetFrameworkVersion>

对我们来说尚不清楚的是如何根据条件指定不同版本的NET. condition属性是一个整数,它返回一个介于1到4之间的数字,并且根据该值,我们应该针对不同的NET框架,当然也可以在app.config中更改此属性

What is not clear for us is how can we specify different versions of NET depending on the condition. The condition property is an int that returns a number, between 1 and 4 and depending on that value we should target a different NET framework and of course change also this property in the app.config

<startup>
   <supportedRuntime version="v2.0.50727"/>
</startup>

我想知道什么是处理此类问题的正确方法.

I want to know what is the right way of handling this type of problem.

推荐答案

您可以在MSBuild文件中依次给出这样的条件.

You can give the condition like this one after other in your MSBuild file.

<TargetFrameworkVersion Condition="$(ConditionProperty) == '1'">v1.1.xxxx</TargetFrameworkVersion>
<TargetFrameworkVersion Condition="$(ConditionProperty) == '2'">v2.0.xxxx</TargetFrameworkVersion>
<TargetFrameworkVersion Condition="$(ConditionProperty) == '3'">v3.5.xxxx</TargetFrameworkVersion>
<TargetFrameworkVersion Condition="$(ConditionProperty) == '4'">v4.0.xxxx</TargetFrameworkVersion>

相应地,您可以编写代码来更改的值

Accordingly you can write the code to change the value of

<startup>
   <supportedRuntime version="v2.0.50727"/>
</startup>

通过以下代码使用变量$(TargetFrameworkVersion)的值,也可以在您的app.cofig文件中

:

in your app.cofig file as well by using the value of the variable $(TargetFrameworkVersion) using the code below:

<XmlUpdate XmlFileName="app.config"
           XPath="//startup/supprtedRuntime[@version]"
           Value="$(TargetFrameworkVersion)" />

这篇关于MSBuild,条件NET运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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