Udostępnij za pośrednictwem


How to: Use an Application Configuration File to Target a .NET Framework Version

You can use an application configuration file to specify which versions of the .NET Framework an application or component supports. You must specify the version and build number of each supported .NET Framework version when you use the <supportedRuntime> Element or the <requiredRuntime> Element in an application configuration file.

The version of the .NET Framework that an application runs on is determined as follows:

  • If the version of the .NET Framework that the application was built against is present on the computer, the application runs on that version.

  • If the version of the .NET Framework that the application was built against is not present and a configuration file does not specify a version in a <supportedRuntime> Element, the application runs on the latest version of the .NET Framework that is present on the computer.

  • If the version of the .NET Framework that the application was built against is not present and the configuration file specifies a version in a <supportedRuntime> Element, the application runs on the latest version that is specified in the application configuration file and is present on the computer.

Note

An application configuration file must have the same name as the application, with a .config extension appended. For example, for an application named MyExecutable.exe, the application configuration file must be named MyExecutable.exe.config.

You can configure an application to run on the version on which it was created or on a later version. For example, an application created with the .NET Framework version 1.0 can target version 1.0, 1.1, 2.0, or all three. An application created with the .NET Framework version 2.0 can target only version 2.0.

Targeting the .NET Framework Version 1.1

The application configuration file entry shown in this section causes an application built using the .NET Framework 1.0 to use the .NET Framework version 1.1 in the following cases:

  • If the .NET Framework version 1.1 is installed.

  • If both the .NET Framework version 1.0 and the .NET Framework version 1.1 are installed.

If only version 1.0 is installed, the application will run because version 1.0 does not recognize the <supportedRuntime> element and will use the version in the PE file header which points to version 1.0.

In the following illustration, MyApp and Assembly A have static references to the .NET Framework version 1.0, while Assembly B has a static reference to the .NET Framework version 1.1. In this example, MyApp has an application configuration file that states that the application supports version 1.1, so the application and Assembly A are redirected to use the .NET Framework version 1.1.

Application configuration file that redirects assembly binding to version 1.1

MyApp example, with Assembly A and Assembly B

To target an application built using the .NET Framework version 1.0 to run on the .NET Framework version 1.1

  • Enter the following XML in the application configuration file:

    <?xml version ="1.0"?>
    <configuration>
      <startup>
        <supportedRuntime version="v1.1.4322" /> 
      </startup>
    </configuration> 
    

See Also

Concepts

Configuring Assembly Binding Redirection

Locating Runtime Version Information

Other Resources

Side-by-Side Execution