Dela via


.NET Framework Multitargeting in Visual Studio 2008 (aka Orcas)

One of the really great features I worked on for our upcoming release is ".NET Framework Multitargeting" for Visual Studio.  This allows you to build applications targeting any of these frameworks using Visual Studio 2008:

  • .NET Framework 2.0 - released with Visual Studio 2005
  • .NET Framework 3.0 - released with Windows Vista
  • .NET Framework 3.5 - will release with Visual Studio Orcas

When targeting .NET Framework 2.0, for example, Visual Studio will try to protect you from using any features that are only available in a higher framework version.  This lets you confidently use Visual Studio 2008 for targeting any of these three platforms.  New projects can be created targeting any of these frameworks, and projects can later be changed to target a different framework.

Why is this so important?

We've heard over-and-over again from .NET developers about how much harder it is to move to the next framework version than to move to the next Visual Studio version.  Upgrading to a new Visual Studio means installing on a few developer machines - upgrading to target a new framework means ensuring that every client of the application has the new framework installed.  Because of this, we very often get asked about whether it's possible to target the older frameworks with the newer tools.  With Visual Studio 2008 - we're enabling just that.

There's another reason this is important for Visual Studio 2008 in particular.  With .NET 2.0, .NET 3.0 and .NET 3.5, we'll have released three framework versions in about 2 years - but only two Visual Studio versions.  Because of this - Visual Studio 2008 needs to be a great tool for targeting both .NET3.0 and .NET3.5, and multitrargeting enables this.  In addition, we want developers and development organizations to be able to easily move from Visual Studio 2005 to Visual Studio 2008 - and support for multitargeting lowers the barrier to entry - you can continue working on your .NET 2.0 applications in Visual Studio 2008.

A few details...

New Project Dialog

The New Project and New Website dialogs now have an additional UI element to choose the framework version to target.  Choosing a target will limit the set of available templates in the dialog.  Additionally, templates that are available for multiple targets will be generated with different default references and usings/imports based on the framework target.  Out of the box, the defaults are to target .NET3.5 - but, just like other options in the dialog, the choice is "sticky", so if you pick .NET2.0, it'll default to that in the future.

Since some templates are unaffected by the .NET Framework target - the description of the template also mentions whether or not a specific .NET Framework target will be applied.

Project Properties

You can change the framework target of your project at any time through the Project->Properties dialog.  If you change the target to a higher framework version, you will be able to use the new API features available in that framework.  If you change the target to a lower framework version, any references in your project which are no longer allowed will be disabled (but left in your References list), and compiling your project will likely result in build failures due to the missing assemblies.  However, we've tried to ensure that changing to a lower framework is easily reversible.

In C# projects, the drop-down to make these changes appears on the Application tab, for VB projects it appears in the Compiler->Advanced... tab and for C++ projects it appears in the Framework and References section. 

Add Reference Dialog

The real heart of multitargeting support is the Add Reference dialog (see "So, how does this work?" below for details).

In the ".NET" tab, references which are not available for the target framework are grayed out and cannot be added.  A hover-tip message explains the reason why.  All the assemblies that ship as part of the higher frameworks will be grayed out, as will any other assemblies which themselves have references to assemblies in the higher frameworks.

In the "Browse" tab, you can still browse to any assembly, but if that assembly requires a higher framework version than your project, a warning dialog will be presented.

Add New Item Dialog

Some of the items that can be added to a project are dependent on a minimum framework version.  For example the "Linq to SQL Classes" item template requires .NET 3.5.  The Add New Item dialog thus filters out these items that are not available for the project.  Custom or third party templates can also set the framework versions they want to be available in - so that they can integrate correctly into this filtering.

Toolbox

The toolbox provides controls from many different assemblies - some of which may not be available for the framework target of your project.  So any controls defined in assemblies which are not available on your target framework will be filtered out of the toolbox.  For example, the ElementHost WinForms control which allows WPF interop as part of .NET3.0 is not available in the toolbox when building a WinForms project targeting .NET 2.0.

Deployment

At the end of the day, .NET framework target is all about deployment prequisites.  So in the Prerequisites dialog we've provided a few options for which .NET Framework package to include with your deployment.

Language

Many of the new language features in the .NET languages can be used with any of the available .NET framework targets.  So Visual Studio 2008 allows you to use C#3.0, VB9, and VC9 for all projects, including those targeting .NET2.0 and .NET3.0.

Websites are different in this regard - you cannot use the new language features in a web site targeting .NET 2.0 or .NET 3.0.  This restriction is in place because Web Sites need to compile on the web server, and this requires that the new compilers be installed on the Web Server.  Since these new compilers come as part of the .NET 3.5 framework, this framework is required on the web server to use new language features.

Express

The Visual Studio 2008 Express products have a limited version of multitargeting.  All of the infrastructure described above is available - except for the dropdown in the New Project Dialog.  This keeps the multitargeting features out of the way for beginning and hobbyist developers - but ensures that projects can continue to move between Express and full versions of Visual Studio as they could in Visual Studio 2005.

 

So, how does this work?

The three frameworks supported by Visual Studio Orcas are each supersets of one another - instead of being replacements as the previous .NET Framework releases have been.  One benefit of this is that .NET Framework Multitargeting can be based just on the available set of references.  That is - when you target .NET3.0, the only things you should be prevented from using are those that depend on assemblies in .NET3.5 - and this can be done by ensuring that you don't accidentally reference these assemblies.

There is one caveat to this - called "red bits".  These are the changes in the framework that are part of .NET Framework 2.0 Service Pack 1 and .NET Framework 3.0 Service Pack 1, both of which will be released along with Visual Studio 2008.  These two service packs are required for .NET3.5 to be installed, and they include a few very targetted additions of new functionality to the .NET 2.0 and .NET 3.0 frameworks.  This means that when you target .NET 2.0 in Visual Studio Orcas, you are really targeting .NET 2.0 SP1.  This is similar to what happens when you are using Visual Studio 2003 after the .NET Framework 1.1 service pack is installed on your machine - so it's really nothing new.  But for those who want to be extra cautious about their framework dependencies, it's somthing to be aware of. 

Try it Now!

Orcas Beta1 is available now, and includes almost all of the multitargeting support described above.  Take a look and let us know what you think.  Orcas Beta2, which will be available later this summer, will include everything described here - along with a ton of other improvements and bug fixes across the rest of Visual Studio 2008 and the .NET 3.5 Framework.  As always, send us feedback through Connect.

Comments

  • Anonymous
    June 29, 2007
    PingBack from http://testsubdomain.netmoviehost.com/net-framework-multitargeting-in-visual-studio-2008-aka-orcas/

  • Anonymous
    June 29, 2007
    So the multi-targeting will not support the .NET 1.1 framework? The company I work for has a lot of applications which are required to be built using the .NET 1.1 framework, but would like to consolidate our Visual Studio development tools.

  • Anonymous
    June 30, 2007
    slace - No - Visual Studio 2008 will not support targeting .Net Framework 1.1.  This is something we really wanted to be able to support - since we know there are a lot of .NET developers working on .NET 1.1 applications.  However, it would have been significantly more difficult to go back and support .NET 1.1 which was a substantially different runtime. Thus, to fit in this release, the decision ended up being either to not support multitargeting at all - or to support only targeting .NET2.0 and greater.  Because we really wanted Visual Studio 2008 to be a great tool for at least both .NET 3.0 and .NET 3.5 - we decided to put in the most multitargeting support we could fit in this release.

  • Anonymous
    June 30, 2007
    The comment has been removed

  • Anonymous
    July 21, 2007
    Multi-targeting FAQ http://dnchannel.blogspot.com/2007/07/multi-targeting-faq.html

  • Anonymous
    July 24, 2007
    As I mentioned the other day, beta2 is coming soon ...VS2008 is the first version of VS that will be

  • Anonymous
    August 06, 2007
    I'm not going to write a long note explaining once again that I've been too busy to post. We all know

  • Anonymous
    August 12, 2007
    There are several good new blogs from members of the Microsoft C# team. Nevertheless, the most important

  • Anonymous
    September 18, 2007
    So you are running Visual Studio 2008 but want to run the .Net 2.0 framework for your applications? Tough

  • Anonymous
    November 06, 2007
    In this blog post, I’ll explain the possibilities and limitations of using solutions and projects between

  • Anonymous
    November 06, 2007
    In this blog post, I’ll explain the possibilities and limitations of using solutions and projects between

  • Anonymous
    November 08, 2007
    Somasegar's WebLog : TechEd Developer in Europe . If you are doing WPF, WCF, and/or WF development this

  • Anonymous
    November 08, 2007
    Somasegar's WebLog : TechEd Developer in Europe . If you are doing WPF, WCF, and/or WF development

  • Anonymous
    March 21, 2008
    I've got some problems with VS 2008 Multitargeting feature. After install VS 2008, my .Net Framework 2 System.Data assembly was somehow replaced for a newer version. The assembly version is the same but the behavior. Since installation the enum System.Data.SqlDbType is the new one with DaTime2, DateTimeOffset, and so on (introduced in .NET Framework 3.5). May it be a bug?

  • Anonymous
    March 21, 2008
    Greg - It sounds like this is related to the "red bits" issue I mentioned near the end of the post.  Installing the 3.5 framework also installs a service pack for the 2.0 framework, and this service pack does include a small number of new types/members.  I believe the things you are seeing are in this category.  Krzysztof has a blog post about some FxCop rules that can help ensure you are not accidentally using this new functionality - if you want to be sure your apps will continue to run on machines which don't have 2.0 SP1. See http://blogs.msdn.com/kcwalina/archive/2007/10/02/Multi_2D00_TargetingAndFxCop.aspx.

  • Anonymous
    April 15, 2008
    About not targeting .NET 1.1....why couldn't you just supporting building to .NET 1.1 with no debug ability...I successfully got VS 2008 to compile in.NET 1.1 but I would like to find a way to add the .NET 1.1 framework tot he list and it could link to the custom MSBuild. Is that possible?

  • Anonymous
    May 30, 2008
    I don't have the option to switch between .net frames in vs 2008, also the code analysis tab are missing?

  • Anonymous
    June 11, 2008
    .NET 1.1 needs to be supported as .NET Framework 1.1 is the only framework that majority of the existing computer today has by default.  I understand you want people to use the newer better framework, but unless you make .net Framework 2.0+ a part of critical updates, Visual Studio 2008 will be completely useless to a huge percentage of developers.

  • Anonymous
    August 09, 2008
    Yes, Please give support for 1.1!!

  • Anonymous
    September 03, 2008
    Yes, please consider re-adding support for 1.1 in VS2008+

  • Anonymous
    October 01, 2008
    I back up the support of targeting v1.1 in VS2008, or otherwise we will need to install both VS2003 and 2008 to develop applications for different versions of .NET application.

  • Anonymous
    October 15, 2008
    "Websites are different in this regard - you cannot use the new language features in a web site targeting .NET 2.0 or .NET 3.0.  This restriction is in place because Web Sites need to compile on the web server, and this requires that the new compilers be installed on the Web Server.  Since these new compilers come as part of the .NET 3.5 framework, this framework is required on the web server to use new language features." You should reword that section of your article because it's extremely confusing.  You make it sound like the code won't compile if you use C# 3.5 syntax in a website.  That is not true. You can use C# 3.5 syntax in website code and it will compile just fine in VS 2008 (I just verified this). It's just that when you deploy it to the server, you'll be in for a rude awakening if you don't have 3.5 framework installed on server.

  • Anonymous
    October 27, 2008
    Thank you for this clear overview of what VS2k8 is capable of.

  • Anonymous
    February 13, 2009
    [Nacsa Sándor, 2009. január 20. – február 12.] Komplett fejlesztő környezet Windows kliens és web alkalmazások

  • Anonymous
    March 16, 2009
    Anyone know where I can get a copy of Visual Studio 2003?  I need to create an application in .NET 1.1 and can't find out where to get Visual Studio 2003 from Microsoft.  I'm knew with the .NET framework. Thanks

  • Anonymous
    July 02, 2009
    I just returned to programming having never used any dot net platform. VB6 was the last one I used. I have no problem with the languages, but the compatibility seems to be as big a mess as COM was. I have downloaded dozens of code samples from MS site and elsewhere for (a) Outlook integration and (b) basic tapi programming. Both areas I have done previously. Not a single code sample will load and run in visual studio 2008. They run through the conversion process and then 20 or thirty errors. I fin things like the outlook object model doesn't support a particular object specified in the sample code etc. Although all the references are there, they are not recognised. Am I missing some important piece of the jigsaw?

  • Anonymous
    July 21, 2009
    The comment has been removed

  • Anonymous
    July 21, 2009
    The comment has been removed

  • Anonymous
    December 11, 2009
    Hello.  Thanks for the writeup. Perhaps my current trouble is related... VS2003/1.1 unable to reference a COM interface (DLL) built in VS2008/3.5.  And interestingly the same work can be referenced by VB6 through the exported TLB file. Is it possible to support multiple frameworks from a single assembly?  How? Thanks, Adam

  • Anonymous
    January 29, 2010
    The comment has been removed

  • Anonymous
    September 17, 2010
    Why Project Windows Forms CLR with .Net Framework 2.0 in Setup Project have dependecies from .Net Framework 3.5 and didn`t work on clear WinXP SP2

  • Anonymous
    July 13, 2011
    I modified the *.csproj to convert vs version 2010 to vs version 2008. But it is not Microsoft's official technology. Can you tell me how to do the same effort?