Click here to Skip to main content
Click here to Skip to main content

How to Use the New Visual Studio 2010 Multi-Targeting

Working on code for projects created in different releases of Visual Studio used to be a big hassle. Visual Studio 2010 improves this and lets you specify the version of the .NET framework and work in its interface while you’re developing in the VS IDE. Click now!

Editorial Note

This article is in the Product Showcase section for our sponsors at CodeProject. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers.

Check out the following helpful resources:

If you’ve ever had to work on code from projects you created in different releases of Visual Studio and the .NET Framework, you know it can be a hassle. You have to have multiple versions available at the same time. Visual Studio 2008 included multi-targeting to help address this issue, and now, Visual Studio 2010 enhances those capabilities. You can easily work on your legacy applications so that you can make the most of what you already have.

Multi-targeting is the ability to specify the version of the .NET Framework that you application requires to run and have the matching experience while developing it with Visual Studio’s Integrated Development Environment (IDE). The nice thing with Visual Studio 2010 multi-targeting is the pervasive support it offers compared to the simple multi-targeting feature that Visual Studio 2008 had.

As an example of this, Visual Studio 2008 IntelliSense always showed the information related to the .NET Framework 3.5, even if you had specified your target to be the 2.0 version. Under Visual Studio 2010, the IntelliSense is now correct: It will show you only what’s available for the version you’re targeting. This means that you can load existing projects or create new ones that target an earlier version of the .NET Framework than the one that ships with Visual Studio 2010 (.NET Framework 4.0). No longer do you need to have different versions of Visual Studio living side-by-side on your machine, just to make sure your software targets the right .NET Framework version. Note, however, that multi-targeting applies only to .NET Framework 2.0 and later.

Get Started

You can open your Visual Studio 2005/2008 solution into Visual Studio 2010 and convert it to the new solution format while still targeting the same version of the .NET Framework. Additionally, as shown in Figure 1, you can let Visual Studio upgrade your solution to the newest version of the .NET Framework when developing a Web site:

image001.gif

Figure 1: Upgrade to the newest version of the .NET Framework

Once your solution is loaded, you can then take advantage of the numerous improvements made to Visual Studio 2010.

When creating a new project, you can specify the .NET Framework version, as you can see in Figure 2.

image002.jpg

Figure 2: Specify the .NET Framework version you want

But you can also change the target framework later on, while you develop, by modifying the Target framework property of your project, as Figure 3 shows.

image003.jpg

Figure 3: Modify the Target framework dialog

In case you have a multi-project solution, you can specify that each project target a different framework version. You can also select a .NET Framework profile that is a subset of the .NET Framework. That profile can provide a limited set of libraries and features (e.g., the client profile). If the profile is not installed on the machine where your software is deployed, downloading it will be faster than previously because the profile is just a smaller subset of the corresponding full .NET Framework.

When installing Visual Studio 2010, you’ll see that one of the components that gets installed is the .NET Framework 4 Multi-Targeting Pack. This is a collection of reference assemblies that help the IntelliSense engine to offer the correct information. Those assemblies are located under %ProgramFiles%\Reference Assemblies and contain only the metadata of the original assembly, not its code.

Side by Side

Talking about the .NET Framework version, it’s important to realize that the NET Framework 2.0, 3.0, and 3.5 all use the Common Language Runtime (CLR) 2.0. The new .Net Framework 4.0 uses a new CLR, version 4.0.

Thanks to improvements starting in CLR 4.0, CLR 2.0 can now coexist with it side-by-side in the same process. No longer is the policy, “Bind to the newest version of the CLR installed.” This will allow you to write shell extensions or managed add-ins, such as the Office ones, in managed code without being afraid of the CLR version already loaded. When a new version of the CLR is released, this same behavior will still be available.

Beware that as far as interoperability is concerned, different CLRs in the same process see each other as another piece of native code. They cannot call each other through the regular CLR mechanism (but you can use COM or Windows Communication Foundation—WCF—for example).

Installing the .NET Framework 4.0 on a machine where 2.0 is installed should not cause any previously running application to break. The application will still be using the CLR 2.0 by default. For ASP.NET, the application pools can now run under one CLR version or the other.

Conclusion

Multi-targeting is one of many new features that Visual Studio 2010 and its companion, the .NET Framework 4.0, bring to your desktop. Multi-targeting now includes targeted API listings in the Object Browser, and targeted property windows for the version of the framework you’ve selected. With the new reference assemblies and the more accurate IntelliSense, you can continue working on your Visual C++ 6 projects in Visual Studio 2010 and leverage work you’ve already done.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Karen Forster
Publisher Platform Vision
United States United States
Karen Forster is Vice President of Platform Vision, www.platformvision.com, and is responsible for building a community around IT decision-making from a platform perspective. She has more than 20 years’ experience in media, publishing, and technology. In 1996, moving from an IBM Midrange computing magazine, Karen took the editorial lead on the start-up Windows NT Magazine (now Windows IT Pro) and its associated web sites and online publications, including newsletters on topics such as Exchange, scripting, security, and IIS. Karen launched SQL Server Magazine in 1999. In 2002, Microsoft recruited Karen to serve as Director of Windows Server User Assistance, bringing her from Colorado to the Seattle area.
Karen has a degree in general linguistics and English as a foreign language from the University of Regensburg, Germany. She lived and worked in Germany for 9 years and returns to visit in-laws frequently. Karen is always interested in hearing about gemuetliche beer gardens in Bavaria.

Comments and Discussions

 
GeneralMy vote of 3 Pinmembersathiswaran16-Sep-10 17:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 11 May 2010
Article Copyright 2010 by Karen Forster
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid