Showing posts with label TipsAndTricks. Show all posts
Showing posts with label TipsAndTricks. Show all posts

Saturday, March 26, 2011

Visual Studio 2010 Tips and Tricks # 5 : Block Editing, Multi-line Coding

  • This is one of my favorite tricks in VS 2010 IDE. This one is more cool than my previous post [Visual Studio 2010 Tips and Tricks #4: Code Snippets ]
  • Did you know you can select any vertical area of your code by using “ALT” key and your “Mouse” in the Code area inside the editor.
  • Say we need to create Model class with lots of string variables and “Get”, “Set”. You can follow the tip#4 and use prop code snippet (or) you can use this Block Editing tip.

Editor_1

  • First select a vertical region of your code by pressing the “Alt” key and selecting a vertical line as shown above.

Editor_2

  • Start typing “public string” and see it fills in all the lines not just one line (as shown above).

Editor_3

  • Now press “Esc” to go out of this mode and start typing your Member names

Editor_4

  • Now again vertical select a region by pressing “Alt” key and use your mouse.

Editor_5

  • And enter “{ get; set; }” and your properties are done.

Editor_6

  • Yes but it looks ugly with lot of spaces in between, so use my previous tip [ Tip to autoformat code ] and select these lines and press “Ctrl + E + Ctrl F” to tidy up the code.

Editor_7

  • When there are lot of similar lines this approach is very helpful to code faster.
  • Say you want to convert all the properties from “public” to “internal”, this can be done very easily using our “Block” editing trick.
  • First use “ALT” key and select all the public word in all the lines.

Editor_8

  • Now start typing “internal” and you just renamed multiple lines. You may ask why not use “Quick Replace” but this is very helpful if you only want to apply the changes to only few lines and not the entire document.

Editor_9

  • This approach is very useful in situations say to enter comments for all lines, say to prefix “M_” or “_” to convert local variables to global etc..

Thursday, March 24, 2011

Visual Studio 2010 Tips and Tricks # 4 : Code Snippets

 

  • This is not a new feature, Code Snippets did exist in previous versions of Visual Studio.
  • Let us look at what are code snippets and how to use them.
  • Trust me they are very helpful for rapid application development. Ninja
  • Assume you are creating a class with member variables and basic getter, setter methods. Now you can sit and write the entire line for each member variable (or) you can make it rapid by following the steps shown below,
  • If you right click on your project and select “Add –> New Class –> enter class name”, it creates the class stub.
  • Now go in to the class and type “prop”

prop_1

 

  • A drop-down gets shown select “prop” and hit tab twice (tab-tab)
  • It will auto-fill the default datatype “int” and puts the “Get/Set” for you.

prop_2

  • Now if you want to change the datatype, click on “tab” and enter say “DateTime” on top of “int”.
  • And click another “tab” and type in your property name and that’s it you just wrote one member variable so fast Party smile

prop_3

 

  • Now having enjoyed rapid authoring, you may be wondering is there more auto-fill’s for most common syntax/structures.
  • Yes there is, for example, say you want to enter try catch. Just enter try and the dropdown shows available snippets,

prop_5

  • Select “try” and hit tab-tab

prop_4

  • Cool right you just saved yourself time entering the braces and aligning them etc..
  • Yes, so your next question is how do I know what all snippets are there, it is very easy,
  • Just right click on your code, select “Insert Snippet” or use short cut key “CTRL + K AND CTRL + X” to show the “Insert snippet” option.
  • Select the folder, say “Visual C#” and see all available snippet options, as shown below,

prop_6

  • Use lot of snippets while you are coding and increase your coding productivity. Nerd smile
  • Become a “Ninja Coder” Ninja
  • Stay tuned for my post about “how to create custom snippets”.

Wednesday, March 23, 2011

Visual Studio 2010 Tips and Tricks # 3 : View Call Hierarchy

 

  • One of the features I like the most with VS 2010 that I use daily is the “Call Hierarchy”.
  • Say you are in a method and you want to know what all methods “Call In” to your method, then this is the most easiest way to do it.
  • Just click on your method and use shortcut key (CTRL + K and CTRL+T) and the call hierarchy window will be shown, or just right-click and select “View Call Hierarchy”.
  • You can keep drilling down.
  • Another nice feature is the “Call Sites” window which is on the Right hand side of the “Call Hierarchy” window. It shows the entire line where the method is called and also gives the file name and the line number. Double click on the row and it takes you to the file.
  • VS 2010 is one of the best IDE’s out there, make full use of it In love

 

Call_hierarchy

Wednesday, March 16, 2011

Visual Studio 2010 Tips and Tricks # 2 : Resolve Namespaces

 

  • With Visual Studio 2010 there is a new feature available called “Resolve”.
  • Using “Resolve”, you can automatically add using statements to a class.
  • Shortcut key to invoke this is => Press Ctrl key and “.” key and automatically the namespace will be added.
  • Shown below in this picture, when we enter “DataSet” and if we press “Ctrl” and “.” keys it automatically shows all the namespaces which have the “Data Set” class.

Resolve_1

 

  • We can move up and down using arrow keys to select the right namespace and then if we click enter, that using statement is automatically added to our using section at the top – “How cool !” Nerd smile

Resolve_2

  • Follow my blog for more tips and tricks like this Angel

Visual Studio 2010 Tips and Tricks # 1 : Navigate To

 

  • With Visual Studio 2010 there is a new feature available called “Navigate To”.
  • Using “Navigate to”, you can search for a file name (or) object name (or) method name in your entire solution.
  • Shortcut key to invoke this is => Press Ctrl key and “,” key to bring up the dialog (like shown below), then start typing your search term and it will auto-fill.

 

Navigate_To

  • In the above picture we can see that it lists filenames that start with “Default” like “Default.aspx” & their entire path location as well as it shows all the classes which have “Default” in their name like example “_default” and also it shows all properties “UseDefaultCredentials”.
  • Also if we click on the search result row, it shows the exact file name and the line number.
  • This is very useful to search in solutions which have lots of projects and files.
  • If you are lazy to type, click on the text and press “Ctrl” and “,” key and it even auto-fills the search text. (like shown below in this image).

 

Navigate_To_1

 

Thursday, May 24, 2007

Codeplex - Microsoft's answer for open source

I was amazed to see the list of open source microsoft projects available at code plex.

Some of the popular ones which we have been using like the Atlas and the Ajax extension sample controls are all from codeplex.
"CodePlex is Microsoft's open source project hosting web site. You can use CodePlex to create new projects to share with the world, join others who have already started their own projects, or use the applications on this site and provide feedback"



The license details are provided here,



Few projects which are very impressive are,


1) BlogEngine.Net - your own dot net blog engine

2) Scorm 2004 implementation for dot net

3) Sharepoint utilities

4) Sandcastle help file builder - for VS2005 IDE (very helpful)

5) Same Desk - brings desktop on the web (unlike silverlight i did not have to install anything to see those applications very impressive) snapshot attached below.

On SameDesk i open a calculator, was able to browse this blog and also search something on the map on the left hand side and the web page looks exactly like a desktop and the app looks like a windows application. :)
you can try this out here live - http://www.openspot.com/


Some implementations given above would take several months if teams were to start coding them from scratch and some i could not believe if it may be completed, but code plex gives the entire source code free.
Every dot net developer should check codeplex without fail.
Also there are server enterprise patterns & implementations.

Friday, May 11, 2007

Visual Studio 2005 Tips & Tricks #1 - Automatically format the code

Visual Studio 2005 Tips & Tricks - Automatically format the Code

I have seen many managers pay more attention to how code is written (mainly to alignment, spacing and indendation), even previous programming languages like FORTRAN 77 & COBOL 65 had particular column numbers where we need to code exactly.

But mainly coding is formated to make it more readable and to look neat for another developer to read and to try to understand.

But most of the developers do not align their code properly making it worse to read and understand, though this is not a new feature in VS2005 it is one of the essential features for any IDE to possess and here it is. Note: It is also present in VS2003, and other famous editors like homesite etc but many developers do not use it and still we see poorly aligned code making it hard to read.

Open the IDE, go to Edit >> Advanced >> Format Document, and
the source and code behind is automatically formated and aligned very neatly with indendation.



Read more tips coming soon on my blog.

Wednesday, February 21, 2007

Classic ASP (not ASP.Net) code debugging with VS Dotnet IDE 2005

I am not sure how many developers would need this but i needed it badly, i think i am the only one doing ASP coding and ASP.Net 2.0 coding at the same time :) So having used the 2005 IDE, you feel like your hand is broken when you go back to do classic ASP coding for old maintenance projects, where only way to debug is Response.Write but imagine how it would be if you can set breakpoint in classic ASP code and step in, step out F11, F10, Shift F11, F5 wouldn't it be great.

So i started my googling to find a solution which would make my daily coding life better and i was able to do it.

So here i am sharing my experience, "How to debug classic ASP using VS Dot net IDE 2005"

1) You need not have a sln or a project file, you can even open one single ASP file and debug it from top to bottom,
2) Open your ASP file in VS Dot net IDE 2005, then open IE and browse the page, this is done so that the ASP rendering process (IIS server but not aspnet_wp.exe, not w3wp.exe but dllhost.exe comes in to task manager),
3) Go to your default web site in IIS or your virtual directory >> right click properties >> home directory >> configuration >> Debugging tab >> in the debugging flags section,
check - Enable ASP server-side script debugging

In the script error messages section, check send detailed ASP error messages to client. (as shown in picture below).


4) Now comes the important step, open your vsdotnet ide 2005, and open the single ASP page and click Debug >> Attach to process >> check the check box [ ] show processes from all users, then look for a process called dllhost.exe Type = x86, Script and the username running it is YOURPCNAME\IWAM_YOURPCNAME.


Click Attach and wait for few minutes and click ok, now go back to your ASP page place a break point and then refresh the IE, and you should see it stops at the breakpoint.

Happy Debugging ASP :)

Tuesday, February 20, 2007

VSDotnet IDE 2005 making use of IIS instead of development webserver

How to use IIS as the default web server instead of inbuilt ASP.Net development web server
When you create a new web project in VS dot net IDE 2005, by default it uses the inbuilt ASP.Net development web server for debugging and running,

So the URL will be something like,
http://localhost:2500 or a dynamic port,

This is actually the internal development web server. But for developers who are familiar with using IIS this may actually be a head ache. Also if you are using port 80 to code certain applications or using AJAX with 80 port then it may be tough to debug using fiddler or in general to stop and restart. So it is better to use IIS.

Listed below are the series of steps which you can easily do to change it to use IIS,
1) Create a virtual directory on IIS and point it to the folder where the source code resides, for example I use D:\drive instead of C:\inetpub\wwwroot, so i create a Virtual directory called "WebSite1" and point it to D:\proejcts\dotnet\website1\ = the folder where the sln file and the vbproj or csproj resides.

2) Right click on the virtual directory tab and go to properties in IIS and click on ASP.Net tab, in the dropdown change the dot net version from 1.1 to 2.0


3) Then open your VS dot net solution file and right click on your project >> go to property pages >> click on start options to see a screen like the one shown below,

In the above screen, select Use Custom server, Base URL: http://localhost/website1
Now try debug >> start without debugging, you will be using IIS to render the page. Though this is simple it takes few minutes to ponder this setting.