Run / Compile Against different dotNet Framework

本文介绍了如何通过配置app.exe.config文件使.NET应用能在指定的.NET Framework版本上运行,即使其包含基于不同版本的组件。此外,还介绍了Visual Studio 2010的多目标特性,该特性允许开发者为不同版本的.NET Framework开发应用。

Configure to make a app run against the same dotNet Framework

For every app, if it has assemblies that are built based on dotNet framework, then it can have a app.exe.config file to support a application level configuration for its running behavior. Some quick understanding about the configuration file content:

1. <startup> element. You can specify which dotNet framework to support for the app even it contains some assemblies are built on dotNet 2.0 and some are built on dotNet 3.5. It means: no matter which dotNet version you use for building assemblies and even use different dotNet versions for different assemblies, by specifying <supportedRuntime> in this element, you can get all of them use dotNet 4.0 for example to run togother without loading CLR 2.0 or 3.5 into the app's process. A key point to use this element is useLegacyV2RuntimeActivationPolicy attribute: it need to be set TRUE so that: if CLR version 4 or later is chosen from the configuration file, mixed-mode assemblies created with earlier versions of the .NET Framework are loaded with the chosen CLR version. Setting this value prevents CLR version 1.1 or CLR version 2.0 from loading into the same process, effectively disabling the in-process side-by-side feature.

More about configuration file.

And see below example from MSDN;

n the following illustration, MyApp and Assembly A have static references to the .NET Framework version 1.0, while Assembly B has a static reference to the .NET Framework version 1.1. In this example, MyApp has an application configuration file that states that the application supports version 1.1, so the application and Assembly A are redirected to use the .NET Framework version 1.1.

Application configuration file that redirects assembly binding to version 1.1

MyApp example, with Assembly A and Assembly B

To target an application built using the .NET Framework version 1.0 to run on the .NET Framework version 1.1

Enter the following XML in the application configuration file:

<?xml version ="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v1.1.4322" />
</startup>
</configuration>

Make use of Multi-targeting of VS2010 to work against different dotNet Framework
The aim of MS of this feature is to encourage user to update to their latest VS IDE without forcing dotNet framework update of user application. This is really business-oriented.

VS 2010 now ships what we call “reference assemblies” for each version of .NET.  A “reference assembly” contains only the metadata of a particular framework assembly – and not its actual implementation (making it much smaller in size on disk).  This metadata is enough, though, to ensure that VS 2010 can always provide 100% accurate intellisense when targeting a particular version of the .NET framework. It also means that properties exposed through the property grid within designers, API listings within the Object Browser, and all the other various places within the IDE accurately reflect the exact API version signature.

We also updated the VS 2010 debugger, profiler and compilers to be able to target multiple versions of the CLR.


 

转载于:https://www.cnblogs.com/taoxu0903/archive/2010/10/27/1862358.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值