Run / Compile Against different dotNet 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/p/1862358.html