Change .NET Framework Target of Compiled Executabl

2019-05-07 00:41发布

问题:

As Windows 8 doesn't contain .NET 2/3.5 by default, I would like to convert some .NET 2.0 compiled executables to .NET 4.5 without re-compiling them with VS 2012. Is there an utility for this task?

回答1:

You could just create or modify the app.config file, and set the supportedRuntime element to 4.5. This will cause the 4.0 CLR (which will use the 4.5 framework) to load the assembly, and does not require any change to the executable itself.



回答2:

As additional information (the solution provided by Reed Copsey works) you can have multiple supportedRuntime elements in order to support systems where 4.x is not installed:

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

And that will make it work nicely in Windows 8 or prior versions where .Net 4.x is not installed.



回答3:

I believe you can't do that as this attributte is backed in the assembly itself (TargetFramework), what you can do if you don't have the source code is to decompile the assembly and recompile it using the desired .NET Framework version.