Visual Studio Assembly force-installs Target Framework

109 views Asked by At

I have this Assembly targeted at .NET 3.5. The code will work on later versions as well, but I like this to work on Windows XP. I mean, .NET is backwards compatible, right? I can run apps for .NET 3.5 on Windows 8.1.

However, when I run my own assembly, it wants to install .NET 3.5 first, even though I already have 4.5.1 installed.

How can I prevent installing 3.5 when something newer is already installed, while remaining 3.5 compatible?

1

There are 1 answers

3
fk2 On BEST ANSWER

The targeted .NET version is the only version that the app will depend upon by default. Visual Studio will not automatically add higher and backwards compatible releases.

Do this manually by adding other .NET versions to a configuration file:

  1. On the Visual Studio menu bar:
    • Choose Project;
    • Add New Item;
    • Choose General from the left pane;
    • Choose Application Configuration File;
    • Name the configuration file appName.exe.config.
  2. Add an item for every .NET version like so:

Code:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v2.0.50727"/>
    <supportedRuntime version="v4.0"/>
  </startup>
</configuration>

See MSDN: Configure an App to Support .NET Framework 4 or 4.5


The .NET Framework 4.5 and its point releases are backward-compatible with apps that were built with earlier versions of the .NET Framework. In other words, apps and components built with previous versions will work without modification on the .NET Framework 4.5. However, by default, apps run on the version of the common language runtime for which they were developed, so you may have to provide a configuration file to enable your app to run on the .NET Framework 4.5. For more information, see the Version compatibility for apps section earlier in this article.

See MSDN