Allow C# application built with .NET 2.0 to run on .NET 4.0/4.5

前端 未结 5 556
一个人的身影
一个人的身影 2020-12-03 03:22

We have a C# DLL (let\'s call it myapp.exe) built with .NET 2.0 Framework (VS2005) and we found out that our application won\'t work on machines where only .NET

相关标签:
5条回答
  • 2020-12-03 03:59

    From: microsoft docs:

    you can choose any App.config file setting.

    0 讨论(0)
  • 2020-12-03 04:10

    Just to be a little more concise. In the App.config you are showing support for the CLR. From .Net v2 and on there are only 2 version of the CLR. So the following will give you support of .Net v2 and on. Make sure to include your exe.config file that is built with your project otherwise you are likely to still see the popup asking to install .Net.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v2.0.50727"/>
        <supportedRuntime version="v4.0"/>
      </startup>
    </configuration>
    

    For support for .Net v2 to v3.5 use:

    <supportedRuntime version="v2.0.50727"/>
    

    For support for .Net v4.0 to 4.6 use:

    <supportedRuntime version="v4.0"/>
    

    More information can be found for Configure an App to Support .NET Framework

    0 讨论(0)
  • 2020-12-03 04:13

    Just setting web.config to supportedRuntime version="v4.0.30319"/ is not going to be enough.

    You need to actually open up your project in Visual Studio, change its target framework (properties-->build) to 4.0 - and THEN redploy the built solution to your 4.0 clients. Several system assemblies are different between 2.0 and 4.0 (system.web etc..) - although, as the previous answer suggested, backwards compatibility has been provided.

    The only way to consistently provide your clients with an actuual '4.0 compatible' version, is to compile it against a 4.0 runtime. This will entail upgrading any 3rd party, open source libraries to their 4.0 versions as well.

    0 讨论(0)
  • 2020-12-03 04:18

    And I quote:

    "The .NET Framework 4 is backward-compatible with applications that were built with the .NET Framework versions 1.1, 2.0, 3.0, and 3.5. In other words, applications and components built with previous versions of the .NET Framework will work on the .NET Framework 4."

    Taken from Version Compatibility in the .NET Framework

    You have the right idea with the App.config file, but your really limiting yourself with the one line.
    Might I suggest a more liberal use of supportedRuntime lines?

    For example:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v2.0.50727"/>
        <!-- 
        <supportedRuntime version="v3.5"/>  "The .NET Framework version 3.0 and 3.5 use version 2.0.50727 of the CLR."  
        -->
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.1,Profile=Client" />
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.1" />
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.2,Profile=Client" />
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.2" />
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.3,Profile=Client" />
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.3" /> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
      </startup>
    </configuration>
    

    Why is supportedRuntime version="v3.5" commented out? Remember, this configuration identifies which versions of the Common Language Runtime (CLR) your application is compatible with. There is no 3.0 or 3.5 version of the CLR. Refer to .NET Framework Versions and Dependencies

    0 讨论(0)
  • 2020-12-03 04:24

    From my testing it would mean that I could run my 2.0 C# application on .NET 4.0 with .NET 4.0 framework (4.0 assembly/libraries) which is contradicting to what the articles said.

    You can run your application on .NET 4 using the .NET 4 assemblies. There is always the possibility that there may be a slight change in runtime behavior, however, as you won't be using the same runtime and framework which you used for development. I suspect the article is trying to suggest that you won't get the exact same behavior by just installing 4.0, though, as you've seen, it should work.

    Doing this is likely fine, though I would recommend doing thorough testing of your application if this is going to be a standard deployment option.

    0 讨论(0)
提交回复
热议问题