Partager via


Visual Studio Multi-Targeting Overview

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

In this version of Visual Studio, you can specify the version of the .NET Framework that is required for your application. Therefore, if you want to use this version of Visual Studio to continue to develop a project that you started in an earlier version, you do not have to change the framework target. You could also create a solution that contains projects that target different versions of the framework. Framework targeting also helps guarantee that the application uses only functionality that is available in the specified version of the framework.

Tip

You can also target applications for different platforms. For more information, see Multitargeting

Framework Targeting Features

Framework targeting includes the following features:

  • When you open a project that targets an earlier version of the .NET Framework, Visual Studio can automatically upgrade it or leave the target as is.

  • When you create a project, you can specify the version of the .NET Framework that you want to target.

  • You can change the version of the .NET Framework that an existing project targets.

  • You can target a different version of the .NET Framework in each of several projects in the same solution.

  • When you change the version of the .NET Framework that a project targets, Visual Studio makes any required changes to references and configuration files.

    When you work on a project that targets an earlier version of the .NET Framework, Visual Studio dynamically changes the development environment, as follows:

  • It filters items in the New Project dialog box, the Add New Item dialog box, the Add New Reference dialog box, and the Add Service Reference dialog box to omit choices that are not available in the targeted version.

  • It filters custom controls in the Toolbox to remove those that are not available in the targeted version and to show the only the most up-to-date controls when multiple controls are available.

  • It filters IntelliSense to omit language features that are not available in the targeted version.

  • It filters properties in the Properties window to omit those that are not available in the targeted version.

  • It filters menu options to omit options that are not available in the targeted version.

  • For builds, it uses the version of the compiler and the compiler options that are appropriate for the targeted version.

Note

Framework targeting does not guarantee that your application will run correctly. You must test your application to make sure it runs against the targeted version. You cannot target framework versions that are earlier than the .NET Framework 2.0.

Selecting a Target Framework Version

When you create a project, select the target .NET Framework version in the New Project dialog box. The list of available project templates is filtered based on the selection. In an existing project, you can change the target .NET Framework version in the project properties dialog box. For more information, see How to: Target a Version of the .NET Framework.

Note

In Express editions of Visual Studio, you cannot set the target framework in the New Project dialog box.

Resolving System and User Assembly References

To target a .NET Framework version, you must first install the appropriate assembly references. Assembly references for the .NET Framework versions 2.0, 3.0, and 3.5 are included in the .NET Framework 3.5 SP1, which you can download from the Microsoft Download Center, Microsoft Visual Studio website. Assembly references for the .NET Framework 3.5 Client Profile, the .NET Framework 4, the .NET Framework 4 Client Profile, and Silverlight are also available from the Visual Studio Downloads website.

Note

A .NET Framework client profile is a subset of the .NET Framework that provides a limited set of libraries and features. For more information about client profiles, see .NET Framework Client Profile.

The Add Reference dialog box disables system assemblies that do not pertain to the target .NET Framework version so that they cannot be added to a project inadvertently. (System assemblies are .dll files that are included in a .NET Framework version.) References that belong to a framework version that is later than the targeted version will not resolve, and controls that depend on such a reference cannot be added. If you want to enable such a reference, reset the .NET Framework target of the project to one that includes the reference. For more information, see Introduction to the Project Designer.

For more information about assembly references, see Resolving Assemblies at Design Time.

Enabling LINQ

When you target the .NET Framework 3.5 or later, a reference to System.Core and a project-level import for System.Linq (in Visual Basic only) are added automatically. If you want to use LINQ features, you must also turn Option Infer on (in Visual Basic only). The reference and import are removed automatically if you change the target to an earlier .NET Framework version. For more information, see How to: Create a LINQ Project.

See Also

Multitargeting .NET Framework Multi-Targeting for ASP.NET Web Projects Platform compatibility and system requirements