简体   繁体   中英

How to deal with .Net framework versions V4.0 vs V3.5 in Windows 8

I need to write a simple program in .net that runs easily on various other people's computers where those people do not have admin rights.

The problem is that Windows 8 no longer (fully) includes .Net 3.5 and earlier.

.Net 3.5 seemed to include the earlier versions, so targeting 2.0 would work with a 3.5 version. But .net 4 no longer seems to include earlier versions the way that .net 3.5 did.

And yet every .net app seems to be bound to a .net version. In combination that would mean that you need to build different versions of your .net application for each version of windows that a user might have. That would be crazy, and Microsoft is generally very good about backwards compatibility.

Having the users install versions of .net is not an option -- they may not have admin rights.

Solution

This seems to work in *.exe.config

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

https://www.devside.net/wamp-server/running-net-3-5-app-on-net-4-5-of-windows-8-and-server-2012

The default Windows 8 install (I just did one to a clean VM) seems to install V1.0, V1.1, V2.0 And V4.0 but only for 32 Bit. Only V4.0 is installed for 64 bit. My .exe did not specify bitness, so defaulted to 4.0, thus no .net. An alternative solution might be to force 32 bit mode.

(I am guessing taht the Framework folder has the 32 bit versions, vs th Framework64 folder)

Haven't tested this out myself, but I believe what you need is exactly the scenario for the supportedRuntime configuration element.

You should then build your application targeting for example framework 3.5 (think it comes built in in Win7), and then add in the app.config file something like the following:

<configuration>
   <startup>
      <supportedRuntime version="v2.0.50727" />
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
   </startup>
</configuration>

Hope that helps.

You can include older assemblies in newer executables, so if you wanted to you could write the application in the oldest version of the framework that you want to support and then create executables for each framework version after that.

For example write everything in a 2.0 DLL and then create 2.0, 3.5 and 4.0 EXEs that just bootstrap the main DLL.

Your user would then just run the version that was installed on their OS.

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