Saturday, May 23, 2009

Code Comment Tracking - A must have tool

23 June 2010: You might find this macro also intereting. It contains two useful methods:
Attach to W3WP so you never need to open the Attach To Process dialog.
Note that the macro is trying to attach to the first w3wp.exe process that is runs under your credentials. If you call the function again, it will attach to the next w3wp available, as sometimes you might have more than just one.
Of course if it doesn't find a w3wp.exe running under your account, it will attach to the first that it finds.

It also contains an Attach To IE function so you can easily debug javascript and attaching to IE.exe.
Note that calling the function multiple times, will attach to the next available IE.exe process.

For an easier use of these macros I suggest you should map your custom shortcuts - I am using alt+3 and alt+4 for these.

How many times have are you looking through some old code and you can't figure out who created that 'weird' thing?
What about when is not your code , isn't hard to look after the fields, methods, properties etc. as they are not in the right order you are used with?

Here is a tool which can help you tracking and arranging the the code.

Have a look on this simple example:
It is weird aligned and it is not commented at all.
there is a certain order every developer respect. For example:
  1. Fields
  2. Constructors
  3. Properties
  4. Events
  5. Util methods
  6. Virtual/Override methods
  7. Business/Static methods
  8. Other classes, delegates, structs etc.
In the left image the code is messed up in a random order, hard to follow.
Of course this is just a small example, but on real code it gets very messy.

Well, that's about to be changed.

As you can notice the code is nicely arranged and well commented.
Now you know when a piece of code was actually created and who to blame on

  • Move code in regions
  • Group regions in an useful order
  • Author and date-time stamp for source-code tracking
  • Automatic xml-doc comment generated for properties i.e. Gets the Name - or - Gets or Sets the Date
  • Automatic xml-doc comment generated for event handlers i.e. Handles the Page's Load event
  • Automatic xml-doc comment generated for event raisers i.e Raises the Init event
  • Automatic xml-doc comment generated for constructors, classes, interfaces, delegates, structs, enums
  • The ability to add the comments/author/timestamp without moving all the code in regions
  • The ability to arrange the code (move in regions) without commenting it
  • The ability to move the code and comment it at the same time
  • The ability to comment the code with the currently logged in user (Environment.UserName)
  • The ability to comment the code with a customized/predefined username or timestamp

How to install it:
  1. Download the attached macro version for VS2008
    or for VS2010
  2. Open Visual Studio 2008/2010, and go to Tools->Macros->Macro Explorer (Alt+F8)
  3. Locate Samples -> Utilities, right click -> Edit
  4. Copy the code from the downloaded file and paste it right after Public Module Utilities
  5. Under project exporer right click References and Add Reference to System.Web.dll version 2.0

  6. Make sure you add on the imports section these lines:
    Imports System.Collections
    Imports System.Text
    Imports System.Text.RegularExpressions
  7. Save the samples (Ctrl+S) and go back in Visual Studio 2008/2010 on Tools->Options->Environment->Keyboard
  8. On 'Show command containing' type PutInRegionsWithoutCreatedAuthor
  9. On 'Press shortcut keys' type your favorite shortcut i.e. Ctrl+Alt+\ (Ctrl+Alt+Backshash) and press Assign
  10. On 'Show command containing' type CommentWholeCode
  11. Select CommentWholeCode if you like your windows login account name to be used for comments, or CommentWholeCodeSpecific if you want to override with your custom name
    To change the specific name locate the CommentWholeCodeSpecific method in the macros editor and fill in your desired name.
  12. On 'Press shortcut keys' type your favorite shortcut i.e. Ctrl+Alt+/ (Ctrl+Alt+Slash) and press Assign
  13. Now go to any class file (*.cs) and test the macros by pressing your shortcuts. eg. Ctrl+Alt+/ and Ctrl+Alt+\

  1. Sometimes VisualStudio goes crazy and shows up an error. To get around it just open the File Search dialog (Ctrl+F) and do a dummy search and run the macros again. The error should be gone. Monday, 6 July 2009, Laurentiu Macovei: This has been fixed and should work smoothly. Also tested on VS2010 and works.
  2. This version only works for .cs files located in CSharp (.cs) projects, or files from App_Code folder within a website
  3. Does not work for stand-alone files (out of solution files)
  4. Does not work for Visual Basic .vb files - just yet

The comment/put in regions operations can be undone by pressing Undo on your document so your document is safe.

The comment feature is intended to be used very often, by all the developers with no exceptions.
Basically every time when you add a new method, property, etc. you should run the CommentWholeCode macro (Ctrl+Alt+/) so it will be commented with your username. Otherwise, some other developer may 'take' your code under his username, and that's not desired.

If you have any questions, please let me know.

Happy code tracking!

Friday, May 22, 2009

Visual Studio 2008 SP1 + Windows Updates and you can't step through .NET Sources!

Visual Studio 2008 with SP1 is great! Especially for the easiness you can debug and step through .NET Framework sources. I'm not going to insist here about how to configure it, there are a lot of articles out there.

Anyway, the happiness is going to end right after you accept Windows Update's KBs. Microsoft has published the sources of a few .NET Framework versions, but of course, unfortunately they are out of date!

As you can see below they only have published the sources of .NET Framework 3.5 SP1 3053 and an update to 3074.

The big issue is that Windows Update automatically brings you the KB51847 update for .NET Framework 3.5 SP1. What they don't tell you is that they are changing .NET Framework 2.0 version from 2.0.50727.3053 to 2.0.50727.3082 and later after other KBs on 2.0.50727.4016.

This change will break your debug and step through .NET Framework sources availability because Microsoft did not publish the PDB (Program Database) symbol files.
After a week of research and wasted time I ended up writing this article and hopefully will help you not to waste it as well.
Of course, Microsoft did not do anything even if I shout on all the channels at them!

In my case, I could not debug System.Web.dll as the downloaded System.Web.pdb was only 912,384 bytes instead of 10,694,144 bytes, the original with the source code included.

The BIGGEST problem is that you cannot ROLL-BACK to 2.0.50727.3053 anymore!

One way to get around this (until M$ will publish out the correct versions) is to download the VHD image with VS2008 sp1 pre-installed and do your quick step-through .NET Framework source code in there. Of course this method requires you to have Windows Server 2008 with Hyper V.

This is how looks in Visual Studio:

Before Modules
After Modules

Source code

Hey Microsoft, are you sleeping on one ear?

Tuesday, May 19, 2009

Visual Studio 2010 Beta 1

Visual Studio 2010 Beta 1 was just launched yesterday, 18th May 09!

Update: 23th May 2009 - Now it's available for everyone for download!

If you are MSDN subscription then you can download it right away. Otherwise you'll just have to wait for a few more days.
Blog powered up by Blogger