How does VS allow you to select the previous .NET platform?

How Visual Studio lets you select a previous version of the .NET Framework when the latest version is a replacement for an earlier version in place. For example, let's say I install .NET 4.6, which is an in-place replacement for .NET 4, 4.5, 4.5.1, and 4.5.2, what exactly happens when I choose version 4 to use?

+6
source share
3 answers

In C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework there are "Reference Assemblies" that have the same open API as older versions, but have no implementation.

While you are coding, IntelliSense uses these reference versions to show you what is available and what a compiler error is. However, when the code is actually compiled, the "installed" version is the one that is actually used and compiled. The reason they can do this is because they maintain 100% backward compatibility for the versions they use to upgrade, so everything written against the 4 APIs will compile without errors in API 4.6 .

+4
source

You have two different things:

  • What version of the .NET Framework are you targeting? You can set this as the Target Framework in properties.
  • What version of the .NET Framework is used when the application is running?

Since some versions are installed in place, even if you target to 4.0 (for example) and 4.5, the application starts using 4.5.

Now what happens in Visual Studio in this case? The answer is that there are reference assemblies for different versions. This way, Visual Studio knows which assemblies, methods, etc. Applicable to the selected target structure and offers only those.

Please note that the application (as I wrote above) can actually work in version 4.5. Thus, although you cannot use the new functions from it directly when targeting 4.0, you can use them through Reflection (but why do this?), And errors and bug fixes that are in version 4.5 but not in 4.0.

+2
source

Choosing an older version, you will not be able to use the latest functions of the framework. However, if you do not need these functions, for example, by choosing version 4, users of your application who have not installed the latest version of the framework will be able to use it without installing version 4.5.2 or 4.6.

-1
source

All Articles