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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top