Sandy
Sandy

Reputation: 1504

How does VS let you select previous .NET framework?

How does Visual Studio let you select a previous .NET framework version when the latest version is an in-place replacement of the earlier version. For example, 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?

Upvotes: 6

Views: 81

Answers (3)

Daniel Rose
Daniel Rose

Reputation: 17638

You have two different things:

  1. What version of the .NET-Framework do you target? You can set this as Target Framework in the properties.
  2. What version of the .NET-Framework is used when the application is run?

Since some of the versions are installed in-place, even if you target 4.0 (for example), and 4.5 is installed, the application gets run using 4.5.

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

Note that the application (as I wrote above) might actually run in 4.5. So while you cannot use the new features from it directly when targeting 4.0, you could use them via Reflection (but why do that?) and might also encounter bugs & bug fixes which are in 4.5 but not in 4.0.

Upvotes: 2

Scott Chamberlain
Scott Chamberlain

Reputation: 127543

In C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework there are "Reference Assemblies" which have the same public API as the old versions but do not have any implementation.

While you are coding IntelliSense is using those reference versions to show you what is available and what is a compiler error. However when the code is actually compiled the "installed" version is the one that is actually used and compiled against. The reason they can do this is because they keep 100% backward compatibility for the versions they do in place upgrades for so anything written against the 4 API will compile without errors in the 4.6 API.

Upvotes: 4

T'lash
T'lash

Reputation: 573

By choosing an older version, you will not be able to use the latest features of the framework. However, if you do not need these features, by choosing the version 4, for example, the users of your application that would not have installed the latest version of the framework will be able to use it without having to install the version 4.5.2 or 4.6.

Upvotes: -1

Related Questions