Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an application target to both 3.5 and 4.5 .Net version?

I write a WPF app, that all source code compatible with both .NET 3.5 and 4.5. That mean if I change .NET target in the Properties to either 3.5 or 4.5, it will complie and run well without any error.
I wonder there is anyway to my my app file can run on both 3.5 and 4.5 .NET pc (example: Windows 7 and Windows 8.1), without complie 2 version for each .NET? Thank!

Edit:
When I copy the .NET 3.5 application in question to a Windows 8.1 pc, Windows refuse to run my app, and require I install .NET 3.5. So if only complie with .NET 3.5, it dont make app can run in .NET 4.5 pc.

like image 624
Thanh Nguyen Avatar asked Dec 31 '13 17:12

Thanh Nguyen


1 Answers

Build with .NET 3.5 and add these lines to App.config and it worked for me:

<configuration>
  <startup>
    <supportedRuntime version="v4.0" />
    <supportedRuntime version="v2.0.50727"/>
  </startup>
</configuration>
like image 128
Thanh Nguyen Avatar answered Oct 30 '22 00:10

Thanh Nguyen