Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How to Use the New Visual Studio 2010 Multi-Targeting

11 May 2010 0  
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!

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here