简体   繁体   中英

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.

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>

have your project target 3.5. then add another project to the solution that targets 4.5 and add links to the files from the first project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM