Multi-Targeting Support (VS 2010 and .NET 4 Series)
page 6 of 8
by Scott Guthrie
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 31515/ 39

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:

Figure 5

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):

Figure 6

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):

Figure 7

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 new Response.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:

Figure 8


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-28 6:45:17 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search