Click here to Skip to main content
Click here to Skip to main content

Peer Code Review Add-in for Visual Studio 2008 - ReviewMyCode

By , 7 Oct 2011
 

Introduction

Peer code reviews are a proven way to improve software quality. ReviewMyCode helps you overcome some barriers to this best practice with a simple Visual Studio 2008 add-in that fits your process. The team members can contribute to the review process without leaving the development environment.

The add-in works well within a team development environment by integrating the review process with the SVN source control management system.

Background

Getting Started with Extending Visual Studio is a good starting point for Visual Studio add-in development.

Using the Code

An add-in must have at least two files, the add-in descriptor XML file and the assembly which implements the actual add-in. The descriptor file describes the add-in assembly and is located in the user's %USERPROFILE%\Documents\Documents\Visual Studio 2008\Addins folder.

A typical add-in descriptor XML file looks like this:

<Extensibility xmlns="http://schemas.microsoft.com/AutomationExtensibility">
	<HostApplication>
		<Name>Microsoft Visual Studio</Name>
		<Version>9.0</Version>
	</HostApplication>
	<Addin>
		<FriendlyName>ReviewMyCode</FriendlyName>
		<Description>Review My Code</Description>
		<Assembly>ReviewMyCode.dll</Assembly>
		<FullClassName>ReviewMyCode.View.Connect</FullClassName>
		<LoadBehavior>1</LoadBehavior>
		<CommandPreload>0</CommandPreload>
		<CommandLineSafe>0</CommandLineSafe>
	</Addin>
</Extensibility>

The Extensibility\Addin\Assembly gives the path to the add-in assembly. With just the file name, Visual Studio will load the add-in assembly from the add-in descriptor folder. If you need to debug the add-in, you need to point it to the debug build of your add-in. Also you need to set up debug properties of the Visual Studio project to start Visual Studio as an external program. Make sure to specify:/resetaddin ReviewMyCode.View.Connect as the command line arguments.

The entry point of an add-in is the Connect class. It implements Extensibility.IDTExtensibility2 interface. The OnConnection method receives notification that the add-in is being loaded and we perform our initialization code here, such as creation of the solution event (Solution Open, Solution Before Closing) delegates. In order to handle solution level events the delegates must be defined in the Connect class.

The OnStartupComplete method receives notification that the host application has completed loading, in which we create our tool window (add-in window) and shows it. The add-in window is a UserControl.

The rest of the classes are just implementing the logic and the UI. Retrieving information about the code being reviewed depends on the selected line. The following code snippet shows the details:

private void ToolStripReviewItemAddNew_Click(object sender, EventArgs e)
{
    TextPoint textPoint = null;
    TextSelection selection = 
        Connect.ApplicationObject.ActiveDocument.Selection as TextSelection;
    if (selection != null)
    {
        textPoint = selection.ActivePoint as TextPoint;
        if (textPoint != null)
        {
            this.textBoxLineNumber.Text = 
            	textPoint.Line.ToString(CultureInfo.CurrentCulture);
        }
    }
    
    CodeElement codeElement = null;
    FileCodeModel2 fileCodeModel =
        Connect.ApplicationObject.ActiveDocument.ProjectItem.FileCodeModel 
				as VCFileCodeModel;
    if (fileCodeModel == null)
    {
        fileCodeModel = Connect.ApplicationObject.ActiveDocument.
        		ProjectItem.FileCodeModel as FileCodeModel2;
    }
    
    if (textPoint != null && fileCodeModel != null)
    {
        // Supported scopes - set up here in the right parsing order
        // from lowest level to highest level.
        // NOTE: Must be adjusted to match any CodeElements supported.
        vsCMElement[] scopes = 
            {
               vsCMElement.vsCMElementFunction,
               vsCMElement.vsCMElementProperty,
               vsCMElement.vsCMElementVariable,
               vsCMElement.vsCMElementEvent,
               vsCMElement.vsCMElementClass,
               vsCMElement.vsCMElementInterface,
               vsCMElement.vsCMElementStruct,
               vsCMElement.vsCMElementEnum,
               vsCMElement.vsCMElementDefineStmt,
               vsCMElement.vsCMElementImportStmt,
               vsCMElement.vsCMElementIncludeStmt,
               vsCMElement.vsCMElementModule,
               vsCMElement.vsCMElementOther
           };
           
        foreach (vsCMElement scope in scopes)
        {
            // Catch and ignore all exceptions from CodeModel.
            // CodeElementFromPoint will raise a COM based exception:
            // System.Runtime.InteropServices.COMException 
            // (0x80004005): Unspecified error.
            try
            {
                codeElement = fileCodeModel.CodeElementFromPoint(textPoint, scope);
                if (codeElement != null)
                {
                    break;
                }
            }
            catch
            {
            }
        }
    }
    
    if (codeElement != null)
    {
        this.textBoxMethodName.Text = codeElement.FullName;
        this.textBoxProjectName.Text =
            codeElement.ProjectItem.ContainingProject.UniqueName;
        this.textBoxFileName.Text = codeElement.ProjectItem.Name;
    }
    else
    {
        this.textBoxMethodName.Enabled = true;
        this.textBoxProjectName.Enabled = true;
        this.textBoxFileName.Enabled = true;
    }
    
    this.textBoxCreatedBy.Text = ReviewWindow.TextToTitleCase(Environment.UserName);
    this.toolStripReviewItemSave.Enabled = true;
}

Points of Interest

Using the Add-in

  • Add-in must be loaded from the Visual Studio IDE. To do this, select Add-in Manager from the Tools menu.
  • To initiate a review, click on "Send to Review" button. This will bring up a new mail message window. Fill in the "To" field and send the mail message to the team members.
  • Reviewers can add review items by selecting review item tab. To modify an item, click on the item in the review list and then select review item tab.
  • A review item can contain comments, such as a rejection comment or comments about the fix.
  • Loading a solution from the Visual Studio automatically loads the current review log from SVN. When closing the solution, the updated review log will be saved in the SVN.

Screenshots

The Review List

The review list

Adding a Review Comment

Adding a review comment

Adding a Comment for a Review Comment

Adding a comment for a review commen

History

  • Oct 5 2011 - Version 1.0.0.0 - Initial version
  • Oct 7 2011 - Added screenshots

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Hilmi Jauffer
Australia Australia
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionUseless at the momentmembersatx_ewallace1 Mar '12 - 10:58 
After tinkering with it for 10 minutes, I still cannot get it to work. Everything is grey. I cannot send anything to review. Maybe some detailed usage instructions would help?
 
Thanks
SuggestionLooks like a very helpful toolmembercwienands28 Feb '12 - 10:31 
I'm looking into whether I can customize it to integrate with our inefficient, Excel template-based code review process (export to Excel, import from Excel).
 
One recommendation: It would be nice if you could include the SharpSvn dependency in the ZIP package and use relative paths in the project files. Otherwise the file paths don't match up and all the references need to be fixed manually.
 
Thanks and greetings, Christoph
QuestionVS.NET 2008 only?membernezza17 Oct '11 - 21:30 
hey,
 
Nice article and the add-in looks really interesting, is it VS.NET 2008 only or will it work in VS.NET 2010?
 
Cheers
AnswerRe: VS.NET 2008 only?memberHilmi Jauffer18 Oct '11 - 9:43 
Hi,
I think it should work. After the installation copy the MY_DOCUMENTS\Visual Studio 2008\Addins\ReviewMyCode.AddIn file to MY_DOCUMENTS\Visual Studio 2010\Addins\ReviewMyCode.AddIn. If the Addins folder is not present create it. Then use the Addins manager in 2010 to start up the addin automatically.
 
Try it let me know. I've never tried it.
 
Regards,
Hilmi.
QuestionHi hilmimemberMember 83001997 Oct '11 - 23:32 
hi auzi guy grade job well done from srilanka guy Lakshitha
QuestionCan You add a Screenshot?membercrashedapp7 Oct '11 - 5:54 
I'm interested in your tool. Maybe a screenshot or two would put in better perspective as to what it actually is used for.
Thanks
AnswerRe: Can You add a Screenshot?memberHilmi Jauffer7 Oct '11 - 10:21 
Hi, Thanks for reading. I have added some screenshots and posted it to the CodeProject. They will update the article soon. Please check out in couple of days.
 
Thanks,
Hilmi.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 7 Oct 2011
Article Copyright 2011 by Hilmi Jauffer
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid