Search code examples
winforms.net-4.0.net-2.0runtimefusion

Is it possible to compile a .NET 2 WinForms application to run on .NET 4, if no .NET 2 is installed?


Recently I got a customer complaint, that a small .NET 2.0 application I wrote did not run on his Windows 7 computer.

After investigating, I found out that there was no folder c:\Windows\Microsoft.NET\Framework\v2.0.50727 on his machine, just the folder for V4.0.

I was unaware that such a constellation is even possible.

My question:

Is it somehow possible to instruct my application to use the .NET 4 runtime, if no .NET 2 runtime is found on a client machine?


Solution

  • I think you're looking for the <supportedRuntime> element in app.config.

    So for example, you can write an app.config file of:

    <configuration>
       <startup>
          <supportedRuntime version="v2.0.50727"/>
          <supportedRuntime version="v4.0"/>
       </startup>
    </configuration>