Tuesday 28 August 2007

Orcas Framework Multi-Targeting

Within Visual Studio Orcas, the concept of framework targeting is introduced.

You can target any project or solution to any of the following versions of the .NET Framework.

.NET Framework 2.0
.NET Framework 3.0
.NET Framework 3.5

Visual Studio 2008 (Orcas) will always use MSBuild Toolset 3.5, which means that regardless of your targeted framework, and even though the code is compatible with .NET Framework 2.0, it will be generated using the latest C#, VB Compiler (not the compiler that shipped with 2.0).

This means that you can use features that produce IL compatible with .NET Framework 2.0 (e.g. Automatic Properties), but you can't use incompatible features (e.g. LINQ).
The code you deploy will be fully compatible, and will reference the dependant assemblies (system, system.data) that shipped with 2.0, but the IL will be produced by the latest compiler.

There is a word of caution here, if you use new language features you will not be able to continue to use Visual Studio 2005 (or existing TFS Build Server, MSBuild (for .NET 2.0)), you also cannot use Websites (not Web Applications), as this is compiled on the website.

If you are paranoid about beta code, then you should therefore develop in Orcas (ignoring new language features, and build in VS2005, or using the earlier version of MSBuild).

Visual Studio 2008 will also stop you from using the features of an earlier framework, until you retarget the framework (which you can do at anytime, (Right Click on Project, Select Properties, Application Tab, Target Framework)
). The support in the IDE is so good, that it will even hide web control specific to .NET Framework 3.5 (e.g. LINQDataSource and ListView).

There is only one gotcha to really be aware of, if you upgrade a solution to Visual Studio (2008), you will need to prat around with the solution to make it work again in Visual Studio 2005 (i.e. the version number in the solution file). This is a bit of a pain, but not the biggest deal in the world (since this is the only change).

No comments: