Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use .Net Framework 3.5 or 4.5 depending on which ever is available

My app uses .net 3.5, and compiles successfully under 4.5 without any modifications, so apparently the libraries my app uses exists both in 3.5 & 4.5. But windows 8 explicitly requires 3.5 even though 4.5 is available.

How can I (programatically) make my app use 3.5 when running on windows7 and 4.5 when running on windows8?

PS: Ideally I want to avoid using an app.config file

like image 806
adentum Avatar asked Mar 31 '12 12:03

adentum


3 Answers

The only thing I could think to do, is to compile for both frameworks. And include both in your installer package, using it to install the correct one based on what you find on the system.

like image 156
Matthew Vines Avatar answered Nov 02 '22 19:11

Matthew Vines


For App developers (and IT Administrators): IT administrators can configure .NET 3.5 apps to run on either .NET 3.5 or .NET 4.5 (depending on what's already installed). In order to run a managed app on either 3.5 or 4.5, just add a section in the application configuration file. This will ensure that if .NET 3.5 is installed, the app will run on .NET 3.5; otherwise the app will run on .NET 4.5. An example of the additional section in the configuration file is provided below:

<configuration>
   <startup>
      <supportedRuntime version="v2.0.50727"/>
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
   </startup>
</configuration>
like image 4
KOMAN Avatar answered Nov 02 '22 19:11

KOMAN


I didn't find a solution which didn't have a dependency on an additional file. But the simplest way I could get my .net 3.5 app to work on windows 8 was creating an app.config file(which I wanted to avoid) and adding the "<supportedRuntime>" element.

<configuration>
  <startup>
    <supportedRuntime version="v4.0" /> 
  </startup>
</configuration> 
like image 2
adentum Avatar answered Nov 02 '22 17:11

adentum