Wednesday, September 9, 2009

Multi-Targeting Support (VS 2010 and .NET 4 Series)

This is the third in a series of blog posts I’m doing on the upcoming VS 2010 and .NET 4 release.

Today’s post discusses VS 2010’s enhanced multi-targeting support – which allows you to use and target multiple versions of .NET. We did significant architectural work in the VS 2010 release to enable a number of new multi-targeting features, and provide a much better experience.

Understanding Side-by-Side

VS 2010 can be installed “side by side” with previous versions of Visual Studio. What this means is that you can install it on the same machine as VS 2008/VS 2005/VS 2003 – and use all of the versions at the same time if you’d like.

.NET 4.0 can also be installed “side by side” with previous versions of .NET on the same machine. .NET 4.0 has a new version number for both the framework libraries and CLR engine – which means it runs completely independently from .NET 2.0, 3.0 and 3.5. What this means is that you can install .NET 4.0 on a machine that has .NET 2.0/3.0/3.5 installed, and configure some applications to run using .NET 4.0 and others to run using the older .NET versions (the IIS admin tool allows you to configure this for ASP.NET applications). This allows you to use .NET 4.0 for new applications - without having to necessarily test and upgrade all your existing ones.

VS 2008’s Multi-Targeting Support

VS 2008 was the first release of Visual Studio that included multi-targeting support for .NET. What this meant was that you could use VS 2008 to create and edit not only .NET 3.5 projects, but also .NET 3.0 and .NET 2.0 projects as well. This allowed developers to more quickly upgrade and take advantage of new Visual Studio tooling features – without having to necessarily require the newer version of .NET to be installed on the clients and production servers running their applications.

VS 2008’s multi-targeting support was able to take advantage of the fact that .NET 2.0, .NET 3.0, and .NET 3.5 all ran on top of the same version of the CLR – and that the primary difference between the .NET versions was in their framework libraries. As a result, Visual Studio’s compilers were able to generate the same IL output, the debugger was able to debug against the same CLR engine, and the IDE support for multi-targeting was primary focused on filtering out new assemblies and project templates from showing up when they weren’t supported with a given .NET version.

This multi-targeting experience worked – although it wasn’t perfect. Intellisense within VS 2008 always shows the types and members for the .NET 3.5 version of a framework library (even if you are targeting .NET 2.0). This means that you can sometimes inadvertently end up using a method that is only in ASP.NET 3.5 even when you are working on a ASP.NET 2.0 project.

VS 2010’s Multi-Targeting Support

We made some pretty major architectural changes with VS 2010 to enable much better and more accurate multi-targeting support.

VS 2010 now ships what we call “reference assemblies” for each version of .NET. A “reference assembly” contains only the metadata of a particular framework assembly – and not its actual implementation (making it much smaller in size on disk). This metadata is enough, though, to ensure that VS 2010 can always provide 100% accurate intellisense when targeting a particular version of the .NET framework. It also means that properties exposed through the property grid within designers, API listings within the Object Browser, and all the other various places within the IDE accurately reflect the exact API version signature.

We also updated the VS 2010 debugger, profiler and compilers to be able to target multiple versions of the CLR.

Using VS 2010’s Multi-Targeting Support

To get a better understanding of how these new multi-targeting features work, let’s create a new ASP.NET Web Application using VS 2010. To-do this we can use the “File->New Project” menu command to bring up the “New Project” dialog. We’ll use the version drop-down at the top of the dialog to filter the project templates to only show those supported with .NET 2.0. We’ll then create a new ASP.NET 2.0 web application project:

step1

Because we are targeting .NET 2.0 with this project, VS 2010 will automatically filter the toolbox and markup intellisense to only allow us to use those controls that shipped in ASP.NET 2.0. Unlike VS 2008, the VS 2010 property grid now automatically filters to only show those properties that were supported on the ASP.NET 2.0 button control:

step2

When writing code, VS 2010 will also now only show code intellisense for those types and methods/properties/events supported with .NET 2.0. Below you can see intellisense for the ASP.NET 2.0 “Response” object when we type “Response.Re”:

step3

When we run the application using the built-in VS web-server, it will run using the ASP.NET 2.0 version (and the VS 2010 debugger will debug the CLR 2.0 process):

step5

Moving a Project from .NET 2.0 to .NET 4.0

We can optionally retarget our project to work with a later version of .NET by right-clicking on the project within the solution explorer and by bringing up its properties dialog. We can select the “target framework” dropdown within it and select the version of the .NET Framework we want to target:

stp8

We can choose from a variety of different .NET versions above. Included in the list is the "Server Core” profile that supports the GUI-less version of Windows Server 2008 R2 – and which does not support certain APIs. Because the reference assemblies we use for metadata and intellisense can support any version or release, we’ll even be able to distribute versions of them with future service packs if they introduce any new APIs (enabling 100% accuracy).

For this walkthrough, we’ll choose to move the project to use .NET 4.0. When we do this, VS 2010 will automatically update the project reference assemblies and the web.config file of our project to properly reflect the new version.

Once we do this, VS 2010 will filter the toolbox and markup intellisense to show us all of the new controls and properties available in the ASP.NET 4.0 version. For example, the property grid below now displays the new “ClientIDMode” property available on all controls in ASP.NET 4.0 - which gives you the ability to control how client id’s are output and avoid ugly client ids (a new ASP.NET 4.0 feature I’ll cover in a later blog post):

stp9

Now that we’ve upgraded the project to use .NET 4.0, VS 2010 will also now show us code intellisense for the new types and methods/properties/events on types in .NET 4.0. For example, below you can see some of the new redirect methods available on the ASP.NET 4.0 “Response” object (which previously did not show up when the project was targeting .NET 2.0):

step7

The new Response.RedirectPermanent() method above makes it easy to issue “HTTP 301 Moved” responses – which can avoid your site accumulating stale links in search engines. The URL Routing engine is now supported by both ASP.NET Web Forms and ASP.NET MVC based applications, and the newResponse.RedirectToRoute() method allows you to easily redirect to a route declared with it.

And lastly when we run the application using the built-in VS web-server, VS 2010 will now run it using the ASP.NET 4.0 version:

step9

Summary

VS 2010’s multi-targeting support enables you to work on projects that target .NET 4.0, .NET 3.5, .NET 3.0 and .NET 2.0. It will allow you to start taking advantage of the new tooling features, without having to immediately upgrade the clients and servers running your application’s to .NET 4.0. The improved multi-targeting support will ensure that this experience is even better and more accurate than before.

Clean Web.Config Files (VS 2010 and .NET 4.0 Series)

This is the first in a series of blog posts I’m doing on the upcoming VS 2010 and .NET 4 release.

Today’s post is about an admittedly small, but I still think kind of nice, change coming with ASP.NET 4.0: clean, simple, web.config files.

You’ll encounter this improvement the first time you do a File->New Project within Visual Studio 2010 and create an empty ASP.NET 4.0 Web application (which is why I thought it might be appropriate to-do as the first post).

Web.config files in .NET 3.0 and 3.5

Over the last few releases, the web.config files within new ASP.NET projects have steadily increased in size. For example: the default web.config file that is added to a new web project in Visual Studio 2008 SP1 is now some 126 lines long, and contains everything from tag definitions to definitions of handlers and modules to be included in the ASP.NET HTTP pipeline.

This increase in size is because .NET 3.0 and .NET 3.5 use the same CLR and machine.config configuration file as those shipped with .NET 2.0 – and simply add and update assemblies in the framework when they are installed. To avoid the risk of us accidentally overwriting customized settings within the original 2.0 machine.config on the machine, we didn’t register the tag definitions, handlers and modules that shipped with the new ASP.NET functionality that came with the .NET 3.0 and .NET 3.5 versions. Instead, we defaulted to having new projects register these settings within the application’s local web.config file instead. This was safer – but caused the web.config files to increase and become more complicated and harder to read.

Web.config files in .NET 4

.NET 4 includes a new version of the CLR, and a new .NET 4 specific machine.config file (which is installed side-by-side with the one used by .NET 2, .NET 3 and .NET 3.5).

The new .NET 4 machine.config file now automatically registers all of the ASP.NET tag sections, handlers and modules that we’ve added over the years, including the functionality for:

  • ASP.NET AJAX
  • ASP.NET Dynamic Data
  • ASP.NET Routing (which can now be used for both ASP.NET WebForms and ASP.NET MVC)
  • ASP.NET Chart Control (which now ships built-into ASP.NET V4)

What this means is that when you create a new “Empty ASP.NET application” project in VS 2010, you’ll find that the new default application-level web.config file is now clean and simple:

The first config section above just tells ASP.NET to enable debugging by default for the application, and indicates the version of .NET that Visual Studio should target when it provides intellisense (VS 2010 supports multi-targeting – and the intellisense within the IDE will automatically vary depending on which version of the framework you are targeting).

The second config section indicates whether to use “integrated” mode when running the ASP.NET application within IIS7 – which controls whether to run ASP.NET HttpModules for all requests within the application or just for the ASP.NET specific URLs. We enable this by default at the application level web.config file for new applications – since for compatibility reasons the default IIS7 setting registered at the machine-wide is to run modules only for ASP.NET URLs (and not for all requests).

Summary

The simplified web.config file in .NET 4 is an admittedly small change – but I think a nice one nonetheless, and one which makes the default experience when you create a new ASP.NET application a little cleaner and more approachable.

In the posts ahead I’ll be delving into many of the more substantial improvements coming with ASP.NET 4. (as well as a few more of the “small but nice tweaks” coming too)

Wednesday, April 29, 2009

Bharathiyin kanavugal

பாரத தேச மென்று பெயர்சொல்லுவார் - மிடிப்

பயங் கொல்லுவார் துயர்ப்பகை வெல்லுவார்.

கங்கை நதிப்புறத்துக் கோதுமைப் பண்டம்
காவிரி வெற்றிலைக்கு மாறு கொள்ளுவோம்
சிங்க மராட்டியர் தங் கவிதை கொண்டு
சேரத்துத் தந்தங்கள் பரிசளிப்போம்.

ஆயுதம் செய்வோம் நல்ல காகிதம் செய்வோம்
ஆலைகள் வைப்போம் கல்விச் சாலைகள் வைப்போம்
ஓயுதல் செய்யோம் தலை சாயுதல் செய்யோம்
உண்மைகள் சொல்வோம் பல வண்மைகள் செய்வோம்.

சாதி இரண்டொழிய வேறிலை யென்றே
தமிழ் மகள் சொல்லிய சொல் அமிழ்த மென்போம்
நீதி நெறியினின்று பிறர்க் குதவும்
நேர்மையர் மேலவர் கீழவர் மற்றோர்.