Fully understanding the .NET versions and backward

2019-04-06 07:37发布

问题:

I have a .NET 2.0 application and I plan to make a 'smart installer' which checks for the available .NET version on the user's PC and install my specific port for it. I saw that:

  • Windows XP (SP2) comes with .NET 2.0
  • Windows Vista comes with .NET 3.0
  • Windows 7 comes with .NET 3.5
  • Windows 8 comes with .NET 4.5

As far as I know, the only thing that's not backward compatible is the CLR version, which is changed after .NET 4.0.

So if I don't want the user to install additional framework just for my application, I should have these versions of my app:

  • .NET 2.0 - XP (SP2 and upper), Vista (3.0 should be able to run 2.0) and 7 (3.5 should be able to run 2.0)
  • .NET 4.0 - if someone installed 4.0 ONLY and have no other
  • .NET 4.5 - for the users that have Windows 8 with no other .NET installed

Am I right? Or 4.5/4.0 are backward compatible?

EDIT: If any of the upper data isn't right, please correct me

回答1:

As far as I know, the only thing that's not backward compatible is the CLR version, which is changed after .NET 4.0.

This isnt true. You can make your .NET2 compiled application run on the .NET4 framework.

You just need to add the following to your app.config:

<configuration>
<startup>
    <supportedRuntime version="v2.0.50727"/>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

Note, I agree with @KingKronus, ie Why not just pick the lowest common denominator?

In your case that would be .NET2 compiled and only one set of pdbs and one compilation set.

Yes, you would need to test your .NET2-compiled app runs OK on the .net4 runtime BUT you would need to test your app in each of the frameworks in your original solution anyway.



回答2:

  1. Actually you don't need to check it manually. Your application will show proper message after you run it and ask user to download and install the needed version.

  2. If you still need to support windows XP, choose .NET 4.0. .NET 4.5 will handle it