Social Networks

ASP.NET 4.0 Visual Studio 2010 New features part 1
ASP.NET 4.0 Visual Studio 2010 New features part 2

This arcticle will describe the new features in ASP.NET 4.0 and Visual Studio 2010 IDE

 

Code Snippets

Code snippets are pre-developed code templates which can save time spent on thinking about the syntax. There are already a lot of built-in code snippets in VS2005 and VS2008. However, those are only available for the code-behind. Code snippets in VS2010 are introduced for JScript, HTML, and ASP.NET markup as well. In the screenshots below, we can see different snippet context menus for JScript and HTML.

Inside the script tag, it would be

aspnet4_1

And inside the HTML:

aspnet4_2

New Profiles

We have seen different development profiles in previous versions of .NET. Like VB, C#, Web Development, and General Development. We select a profile based on our priorities. These are selected after the first installation of Visual Studio or from the Import Export option.

aspnet4_3

In VS2010, two more profiles are introduced and both support HTML developers. Those are:

1) Web Development
2) Web Development (Code Optimized)

aspnet4_4
The Web Development profile hides the client objects and events bar on top in HTML mode.

aspnet4_5

In Code Optimized, you will find the HTML editor without code, and the designer tabs. So, it provides a more bigger area on the screen to play with HTML.

aspnet4_6

You can choose a profile after installation of Visual Studio on first use. You can also change the existing working profile from the Tools > Import & Export Settings > Reset all settings option. You will have to open and close Visual Studio if it does not show the changes in the IDE.

Generate From Usage

In previous versions of ASP.NET, Microsoft introduced code refactoring to generate methods and identifiers from existing code. In ASP.NET 4.0, there is a new concept of Generate From Usage – generates properties, methods, classes, and other types based on existing code.

Write some code, select it and right click on the left most character, and you will get options to change it to a property or method etc. This option is shown only if you do not define an identifier. For example, in the following example intellisense, it will not show the options to extract a property if you right click on the variable i.

aspnet4_7

Multi-Targeting

In VS2008, it is possible to create a project in version 2.0 or 3.0, rather than developing in default 3.5. Also, there is an option to change a developed project’s target framework version.

The same option is available in VS2010, but with one improvement. In the previous versions, if you create a project in framework 2.0, intellisense will still show you the types and members of 3.5 version as well, so there are more chances of error if you cannot identify the member of the chosen framework. But in VS2010, the intellisense will show you options for the appropriate framework only.

Multi-Monitor

Visual Studio 2010 provides us facility to move windows of the IDE outside of the Visual Studio IDE and place them on the desktop area. It also supports having different IDE windows on multiple monitors. If we close Visual Studio and open it again, we will find all the windows on the same places where we finished them last time.

aspnet4_8

Code Navigation in Class Files

Code Navigation

A new Navigate To option gives us facility to search a term in a file more quickly. It searches the text as you type, but it works for class files only, i.e., it doesn’t work for HTML or code-behind files. In the following example, it shows the function name as I type it in the Navigate To window; on selection of any, it will navigate to the function definition.

aspnet4_9

View Call Hierarchy

This featrure helps to see the use of a function and its properties. For example, if you right click on a function name, it will show you the hierarchical list of function usage.

aspnet4_10

If you click View Call Hierarchy, it will show you a window with the details of the function calls:

aspnet4_11

On selection of the function call in the hierarchy window, it will show the details of the parameters and the location of the function call.

aspnet4_12

Code Identifier Highlighting

On selection of an identifier, the IDE will highlight the places for you where it is utilized. For example, I selected variable i and it highlights the different places it is used.

aspnet4_13

Intelligence Improvements

In VS2008, on selecting properties for an object, intellisense will show you the properties based on the alphabetical order as you type.

In VS2010, it shows you the properties based on groups. For example, if you type text for a text box, it will show you the members based on the word text, like Text, TextChanged, TextMode. It also supports Pascal case intellisense. For example, if you type TC, it will navigate to the TextChanged member.

aspnet4_14

In the picture below, you can see the ClientIDMode property in version 4, and if we change its target version from project properties, it will not show this attribute for the textbox.

aspnet4_15

EnablePersistedSelection

On selecting a row in controls like DataList or GridView, if we move to another page index, it selects the same numbered row on the newly selected page, although we selected it only on the first page.

To avoid this, ASP.NET 4.0 has introduced a new property for these controls, called EnablePersistedSelection. If you set it to true, it will not select the same numbered row on other pages, and on navigation to the original page, for example, the first page, it will show the initially selected row as selected.

Web.Config Transformation

Normally, we set some values in web.config for the development environment, and then we change those values manually at the time of deployment or testing.

For example, if we have a connection string or any key value combination in the web.config file, and we want to replace those at the time of project publishing or deployment, then we can use the new web.config transformation. It is an automatic way to perform this operation.

Web.config settings can be overridden by other config files like web.release.config, web.debug.config etc., at the time of debug, release. These values are not overridden in the original web.config but in the published web.config.

With the help of transformation, we can replace, remove, or delete a node, and for a node itself, we can remove or set attributes. For example:

1) Create a config file from Configuration Manager > New:
aspnet4_16
2) Name it TransformWebConfig. Select Release from the Copy settings from option:
aspnet4_17

This will create TransformWebConfig.config.
aspnet4_18

3) Right click on web.config and select the Add config transfroms option. Open the web.config and add a test key and the value to be changed.

<appSettings>
  <add key="KeyOne" value="A value"/>
</appSettings>

4) Open TransformWebConfig.config and add the following line to it:

 <appSettings>
<add key="KeyOne"
    value="TestOnConfigurationConfig"
    xdt:Transform="Replace"
    xdt:Locator="Match(key)" />
</appSettings>

Set the xdt:Transform attribute to Replace.
Right click on the project and select Create Package. VS will get the values from the TransformWebConfig.config file, and it will change the value in the published web.config file for us.
On successful build, go to the obj folder and check the web.config file under the TransformWebConfig folder; you will see the value TestOnConfigurationConfig for the key KeyOne.



None found.

Leave a Reply

Your email address will not be published. Required fields are marked *

Allowed Tags:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>