BuildManager.TargetFramework Property

Definition

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

public:
 static property System::Runtime::Versioning::FrameworkName ^ TargetFramework { System::Runtime::Versioning::FrameworkName ^ get(); };
public static System.Runtime.Versioning.FrameworkName TargetFramework { get; }
static member TargetFramework : System.Runtime.Versioning.FrameworkName
Public Shared ReadOnly Property TargetFramework As FrameworkName

Property Value

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

Remarks

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 Sites that Target the .NET Framework 2.0

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.

Applies to