This is the first in my blog series on Visual Studio 2010 Designer Multi-Targeting

When creating a new project in Visual Studio, you must select which framework you’re targeting:

NewProjectTargetFramework

This setting is stored in your project file:

  <PropertyGroup>
    ...
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
  </PropertyGroup>

When you build this project, msbuild will automatically inject a TargetFrameworkAttribute into the assembly to indicate which framework it was compiled against.  Note, this attribute was added in .NET 4.0 and will not be injected when targeting previous frameworks:

TargetFrameworkAttributeIL

Also notice that the toolbox automatically knows when to filter out controls from this assembly.  The first image below shows the toolbox for a project targeting 4.0, where both a 2.0 and a 4.0 control are available:

ToolboxFiltering4_0

When the project is updated to target framework 2.0, notice that the 4.0 control is no longer available:

ToolboxFiltering2_0

Each control in the toolbox is assigned a minimum target framework based on which assembly it came from.  The toolbox compares this minimum framework against the current project’s target framework to determine whether the control is supported.  For details on how to obtain the minimum framework, see IVsTargetFrameworkAssemblies.