Share via


Visual Studio Multi-Targeting Overview

The multi-targeting feature of Visual Studio lets you specify the specific version or profile of the .NET Framework that is required for your application. The key benefit of multi-targeting is that you can use the current version of Visual Studio to create and develop projects that target an earlier version of the .NET Framework. For example, you can continue to develop projects that were created in Visual Studio 2005 and Visual Studio 2008 without adding new .NET Framework dependencies. Multi-targeting helps guarantee that applications use only functionality that is available in the specified .NET Framework version. In addition, multi-targeting lets you continue to deploy older applications without requiring you to add a new .NET Framework version in your deployment package.

Note

Multi-targeting in Visual Studio does not guarantee that your application will run in multiple versions of the .NET Framework. You can use multi-targeting to select a.NET Framework version target for your application. You still must test your application to make sure it runs against the selected version. Multi-targeting in Visual Studio applies only to .NET Framework 2.0 and later versions.

.NET Framework Versions and Profiles

Visual Studio 2010 includes only the .NET Framework 4. To target earlier versions of the .NET Framework, you must have the .NET Framework 3.5 Service Pack 1 (SP1) installed. The .NET Framework 3.5 SP1 includes the .NET Framework 2.0, the .NET Framework 3.0, and the .NET Framework 3.5 SP1. To download and install the .NET Framework 3.5 SP1, see Microsoft .NET Framework 3.5 Service Pack 1 on the Microsoft Download Center Web site.

A .NET Framework profile is a subset of the .NET Framework that provides a limited set of libraries and features. An example of a Framework profile is a client profile that can be used to create client applications. For more information about the client profile, see .NET Framework Client Profile.

You can specify the target .NET Framework version or profile by selecting it in the New Project dialog box when you create a project. The list of available project templates is filtered based on the selection.

Note

Multi-targeting through the New Project dialog box is not available in Express editions of Visual Studio.

Changing the Target .NET Framework Version

For an existing project, you can change the target .NET Framework version or profile by modifying the project properties. For more information, see Application Page, Project Designer (C#) and Advanced Compiler Settings Dialog Box (Visual Basic).

When you change the target .NET Framework version, Visual Studio does not always change the versions of referenced assemblies automatically. Some manual changes may also be required. For more information, see Troubleshooting .NET Framework Targeting Errors.

Multi-Targeting Features

Visual Studio multi-targeting includes the following features:

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

  • When you create a new 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 is targeted for.

  • You can target different versions of the .NET Framework in different 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.

In addition, when you work on a project that targets an earlier version of the .NET Framework, Visual Studio dynamically makes changes in the development environment, such as the following:

  • It filters items in the New Project dialog box, in the Add New Item dialog box, in the Add New Reference dialog box, and Add Service Reference dialog box to omit choices that are available only in later versions.

  • It filters custom controls in the Toolbox to remove those that are available only in later versions, and to show the latest version when multiple controls are available for the targeted version.

  • It filters IntelliSense to omit language features that are available only in later versions.

  • It filters properties in the Properties window to omit those that are available only in later versions.

  • It filters menu options to omit options that are available only in later versions.

  • It compiles and builds with the appropriate version of the compiler and with the appropriate compiler options.

Developing Applications Compatible with Multiple Versions of the .NET Framework

To develop an application compatible with multiple versions of the .NET Framework, we recommend that you develop your application against the lower version of the .NET Framework and then build against the higher version of the .NET Framework. For example, you can develop your application against .NET Framework 3.5 and build against .NET Framework 4.

Resolving System and User Assembly References

The Add Reference dialog box disables system assemblies that do not pertain to your target .NET Framework version. (System assemblies are .dll files that are part of a .NET Framework version.) This helps you avoid adding references to assemblies that are not in your target version. If you modify your project file to include references that belong to a .NET Framework version that is newer than the one currently targeted by your project, your reference will not resolve. Also, you cannot add or use controls that depend on this reference. You can resolve this reference by switching the .NET Framework target of your project to one that includes this reference. You can do this on the project Property Page. For more information, see Managing Project Properties with the Project Designer.

Enabling LINQ

When you move a project to 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 when you change the target .NET Framework version to 3.0 or 2.0. For more information, see How to: Create a LINQ Project.

See Also

Concepts

.NET Framework Multi-Targeting for ASP.NET Web Projects

Other Resources

MSBuild Concepts