BuildManager.TargetFramework Property

.NET Framework (current version)

The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets the target version of the .NET Framework for the current Web site.

Namespace:   System.Web.Compilation
Assembly:  System.Web (in System.Web.dll)

public static FrameworkName TargetFramework { get; }

Property Value

Type: System.Runtime.Versioning.FrameworkName

The target version of the .NET Framework for the current Web site.

This property supports the ASP.NET multi-targeting feature, which enables you to use the latest version of Visual Studio to develop applications that will run with earlier versions of the .NET Framework. A build provider can use this property to make sure that the provider generates code that is appropriate for the targeted version of the .NET Framework. For example, you might want to generate different code depending on whether a Web site targets the .NET Framework 3.5 or the .NET Framework 4. For more information about multi-targeting, see .NET Framework Multi-Targeting for ASP.NET Web Projects.

If the Web site does not have a Web.config file, ASP.NET assumes that the target framework version is the version that is associated with the IIS application pool that the site is running under. For a file-system Web site that is running in Visual Studio, the default framework version is the current version of the .NET Framework.

If the Web site does have a Web.config file, ASP.NET determines the target framework by examining the Web.config file.

Web applications that target the .NET Framework 2.0 are compiled as if the target were the .NET Framework 3.0. The build process does not differentiate between the .NET Framework 2.0 and the .NET Framework 3.0 because the Web.config file does not indicate compiler version or target framework when one of those versions is targeted. (For the .NET Framework 3.5, the Web.config file specifies the compiler version, and for the .NET Framework 4, the Web.config file specifies the target framework.) Therefore, for Web applications that target the .NET Framework 2.0, this property returns a target framework moniker that indicates the .NET Framework 3.0.

This normally will not cause any problems. Visual Studio prevents you from creating references to .NET Framework 3.0 features in a project that is targeted for the .NET Framework 2.0. For example, Visual Studio does not provide item templates for WCF services in a project that is targeted for .NET Framework 2.0, because WCF was introduced with the .NET Framework 3.0 and is not compatible with the .NET Framework 2.0.

If you plan to deploy a Web site in a .NET Framework 2.0 run-time environment and you use a tool other than Visual Studio to reference features that are compatible only with .NET Framework 3.0, the project might build without generating errors or warnings. However, the application might generate errors when the Web site runs on the .NET Framework 2.0.

.NET Framework
Available since 4.0
Return to top