Visual Studio Managed Multi-Targeting: Part 1: Concepts: Target Framework Moniker, Target Framework

Visual Studio Managed Multi-Targeting: Part 1: Concepts: Target Framework Moniker, Target Framework

Rate This
  • Comments 6

In prior versions of Visual Studio, before Visual Studio 2010, the projects could only target .NET Framework versions v2.0, v3.0 and v3.5 therefore it was, mostly, sufficient to identify a framework only with its version.

This is changing with Visual Studio 2010 – now projects will be able to target not only current versions of the .NET Framework, but they will also be able to target future versions of the .NET Framework and even target other framework-families like Silverlight. In other words Visual Studio 2010 supports true multi-targeting and truly extensible multi-targeting.

Now suddenly the version itself is not sufficient to describe a Target Framework; we need a new kind of moniker to describe/identify frameworks in the extensible multi-targeting world.

Enter the Target Framework Moniker.

Target Framework Moniker

A Target Framework Moniker is a textual representation of a moniker that uniquely identifies a Target Framework.

It generally takes the form:

<Target Framework Identifier>,Version=v<Target Framework Version>,Profile=<Target Framework Profile>

Examples are:

  • .NETFramework,Version=v4.0

  • .NETFramework,Version=v4.0,Profile=Client

  • Silverlight,Version=v3.0

Thus the Target Framework Moniker has at the most 3 components; the Identifier, Version and a Profile.

The Identifier and the Version are mandatory while the Profile is optional. 

Target Framework Identifier: is the identifier for the framework-family of the Target Framework; examples of the framework-families are .NETFramework, Silverlight etc.

Target Framework Version: is the text representation of the numeric version of the Target Framework e.g. .NET Framework framework-family has versions v2.0, v3.0, v3.5, v4.0 or maybe in the future say v4.5.

A slight but important digression to clear up a common source of confusion; there is often uncertainty and confusion around the version numbers of Visual Studio, .NET Framework and CLR and especially the latter two. There is also often confusion about their relationships.

Visual Studio, .NET Framework and CLR have all their own independent versioning schemes e.g. Visual Studio 2003, 2005, 2008 and now 2010; .NET Framework v2.0, v3.0, v3.5 and now v4.0; CLR 2.0 and now 4.0

Visual Studio is always built using the latest version (at the time of its release) of .NET Framework and CLR. A particular version of .NET Framework is built on a particular version of the CLR.

E.g. Visual Studio 2010 is built on .NET Framework v4.0 and CLR 4.0. .NET Framework v3.5 is built on CLR 2.0.

Projects within Visual Studio 2010, directly, always target a particular version of the framework-family e.g. .NET Framework; projects never directly target a particular version of the underlying runtime for that framework-family e.g. CLR which is the underlying runtime for .NET Framework.

The following table, hopefully, makes the above discussion clear:

.NET Framework Version Is built on CLR version
v2.0 2.0
v3.0 2.0
v3.5 2.0
v4.0 4.0
vFutureVersion 4.0
vAnotherFutureVersion CLRFutureVersion

Projects in Visual Studio version Can target
Visual Studio 2008 .NET Framework v2.0/v3.0/v3.5
Visual Studio 2010

.NET Framework v2.0/v3.0/v3.5/ v4.0/vNext

Silverlight v3.0/v4.0

AnotherFrameworkFamily vXXX

A key take away from all the above – if you want to pick one - is that Visual Studio projects always, directly, target a framework-family (e.g. .NET Framework) version and not the underlying runtime (e.g. CLR) version.

Coming back,

The third and optional component of the Target Framework Moniker is the Profile.

Target Framework Profile: To understand profiles we need to understand Target Frameworks better and also understand full/base Target Frameworks better. Therefore we shall discuss this in detail later in this blog. Meanwhile, in brief, the Profile is a targetable framework that is a subset of a Full Framework. For example, the Profile .NETFramework,Version=v4.0,Profile=Client (Display name: .Net Framework 4 Client Profile) is a subset of the full/base .NETFramework,Version=v4.0 (Display name: .Net Framework 4) Target Framework.

The Target Framework Moniker is a key to deduce the disk layout of the Target Framework’s Reference Assemblies. This will be discussed in a subsequent blog.

Just to provide some visuals, here are some of the areas you may encounter the Target Framework Moniker:

While creating a new project:

On the VB/C# project properties page:

Please note that Visual Studio 2010 only shows the .NET Framework framework-family in the “New Project Dialog” and this is by design. But you can still open projects targeted to other framework-families like Silverlight in Visual Studio 2010. When you create a Silverlight project it actually targets the Silverlight framework-family.

What you see in the visuals above are the display names of the Target Framework. The display name is different from the Target Framework Moniker itself and is a display only string provided by the Target Framework Provider in the RedistList/FrameworkList.xml. The RedistList will be discussed later in a subsequent blog about Reference Assemblies.

Target Framework

Even though the general concept of a Target Framework is probably generally understood by now – it is time to dive into the precise details of the Target Framework concept.

Target Framework is the design time manifestation of a runtime framework. For example Target Framework .Net Framework 4 represented by the moniker .NETFramework,Version=v4.0 is the design time manifestation of the corresponding runtime framework.

Target Frameworks are a design time concept. The corresponding runtime framework needs to be installed for the project’s output application/module to run.

Target Framework is used by Visual Studio (and other tools like Expression Blend) and build environments to provide a design time environment to the project so that the executable/module produced/built there-forth is guaranteed to run on the corresponding runtime framework on any machine.

It helps a developer by preventing them from using a Type from a framework, in their project, which is not a runtime prerequisite for their project output binary.

Target Framework consists of a set of reference assemblies and supporting files on disk laid-out in a specified directory structure. Reference assemblies are the only source of static metadata and type information for a Target Framework. Reference assemblies and their layout will be discussed in detail in a subsequent blog in this series.

In general Target Framework refers to the Full/Base Framework e.g. .NETFramework,Version=v4.0. When targeted to the Full Framework the project can use the full surface area in that framework.

Some key Framework deployment scenarios may not require all the Types/surface-area in the Full Framework and therefore the framework provider may provide a Profile Framework instead e.g. .NETFramework,Version=v4.0,Profile=ServerCore. The Profile only exposes a subset of the surface area of the parent Full Framework e.g. .NETFramework,Version=v4.0; this subset may be a reduction in the number of assemblies, or in the number of Types in the assembly, or even a reduction in the members of a Type. Profile cannot add any new surface area – it is always a subset/reduction. Profiles are the preferred delivery mechanism for “parts of a Full Framework”. The Profile framework is available to be targeted by a project, independently, just like any other Full Framework.

Consider this user story to understand Target Frameworks better:

Mark is a .NET developer. His development machine currently has Visual Studio 2010 and the .NET Framework v4.0. He develops web based inventory management software for a major distribution company. This software runs on a highly secured Windows Server 2008 machine and requires only .Net Framework v4.0 installed to run. In the course of using his development machine he finds he needs to install a new version of his company's document management application which requires .NET Framework v4.1. The v4.1 framework included changes/additions to System.web. Now Mark's Visual Studio project needs the v4.0 System.Web assembly (or only Type metadata from the said assembly) in order to make sure that additions in the v4.1 System.Web is not inadvertently included in his project. Without the v4.0 Target Framework Mark's project/application may inadvertently use v4.1 types, which will cause the application to fail when deployed.

To re-iterate the crux of the user story above - without the concept of the Target Frameworks and separate Target Frameworks for v4.0 and v4.1, the above developer may have inadvertently used Types from the v4.1 assembly thus rendering their application incapable of running on a machine with only v4.0 installed which is their only runtime pre-requisite. Issues like this can only be caught via deployment testing late in the product cycle.

Conclusion

This Visual Studio Managed Multi-Targeting series pertains to managed project systems and aims to provide a detailed round-up of all relevant/related topics.

Please feel free to use the comment stream to ask questions.

Binu N. Chacko – Software Developer, Visual Studio Platform Team.
Biography: Binu joined the Visual Studio team during the early stages of Visual Studio 2010. Prior to joining the Visual Studio team in early 2008; Binu spent eight years contributing to Windows XP, Windows 2003, Windows Vista, and System Center Configuration Manager 2007/R2 products – within Microsoft. Prior to that – outside/before Microsoft - he worked on helping deliver several versions of Canon’s premier Document Management System product. For Visual Studio 2010, Binu was a key contributor to the extensible multi-targeting core platform, solutions and the VB/C# project system core platform. Binu lives with his wife and the two joys of his life – his two sons – in Seattle, Washington; and loves cricket, soccer, theatre and movies.

Leave a Comment
  • Please add 1 and 5 and type the answer here:
  • Post
  • Good thing you posted this again, because I was meaning to ask about this but the comments were disabled before.

    How does the build system and targeting handle the different compiler versions? Will Visual Studio 2010 be able to target .NET vNext and will it be able to use newer versions of the C# compiler?

  • Thank you for submitting this cool story - Trackback from DotNetShoutout

  • Love the blog.  I have a semi-related question for you:  With VS 2010, on a 64-bit development machine, when I create a new solution, it defaults to the "x86" platform instead of "Any CPU" (and further, I have to manually create an "any cpu" profile in the configuration manager.  Why is that?  Is there a way I can change it to default to AnyCPU?

  • @Michiel

    The build system is heavily involved in multi-targeting; indeed it is responsible for reference resolution and determining which references are allowed in a particular target.

    For the compiler specifically: the same 4.0 C# compiler is used to target previous frameworks back to 2.0; since it's given the explicit set of references to use including mscorlib, I would naively assume it doesn't have to change much between targets beyond change the header it puts on the emitted assembly. I don't know about VB, but again, the right thing is done.

    I don't know about future versions of VS. If it didn't allow you to use the latest C# compiler at the time it shipped, that would be quite odd.

    Dan

  • @J.M.: Please see [1] and [2] for reference.

    [1] connect.microsoft.com/.../ViewFeedback.aspx

    [2] blogs.msdn.com/.../anycpu-exes-are-usually-more-trouble-then-they-re-worth.aspx

  • "I don't know about future versions of VS. If it didn't allow you to use the latest C# compiler at the time it shipped, that would be quite odd."

    Of course, and that's not what I meant. I mean to ask a question in response to the second paragraph:

    "This is changing with Visual Studio 2010 – now projects will be able to target not only current versions of the .NET Framework, but they will also be able to target future versions of the .NET Framework"

    What I want to know is, will Visual Studio 2010 be able to use a future version of the C# compiler?

    Thanks!

Page 1 of 1 (6 items)