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

Code Review Plug-in for Visual Studio 2008, ReviewPal

By , 4 Nov 2009
 
Sample Image - maximum width is 600 pixels

Introduction

Code Reviewing is a must for a software project/product to maintain the code quality (indirectly the overall quality) and to share knowledge by pointing out best practices, etc. There are not lots of tools out there to help out with code reviews and not all those tools fit into organizational needs. What this tool does is that it makes it really easy to do code reviews and to address the review comments easily with less effort.

Background

Doing code reviews or addressing them by the owner of the code can be done even without using tools. It can be done even with an Excel file, where the reviewer reports his comments on an Excel file and passes it to the code owner and he addresses the comments by navigating to the code areas mentioned on the Excel file. But is this something we should do as professionals giving software solutions to others?

This process should be very much integrated with the development IDE, and neither reviewer nor the developer should have the need to switch to other unrelated applications in the code review process (unless really needed, not just to read the comments and navigate to the correct place).

So my idea was to search for an IDE plug-in to help with this, where reviews can be done totally within the IDE itself. Not being able to find such a tool exactly the way I wanted, I thought of developing one.

Using the Code

This is a plug-in for the Visual Studio IDE, so all you have to do this is deploy the plug-in and enable it, to use it. If you are not interested in the code and you would just like to try it out, all you have to do is download the "ReviewPal Add-In binaries" and copy it to the plug-in directory.

Plug-in Location: C:\Users\Chathuranga\Documents\Visual Studio 2008\Addins for my machine on Windows 7.

How Visual Studio plug-ins work is through the ".AddIn" files. At the startup of the VS IDE, it looks for the plug-in location usually "Visual Studio 2008" folder under current users documents folder and loads those Add-ins. These .AddIn files are just XML files, like the one below:

<?xml version="1.0" encoding="UTF-16" standalone="no"?> 
   <Extensibility xmlns="http://schemas.microsoft.com/AutomationExtensibility"> 
      <HostApplication> 
       <Name>Microsoft Visual Studio</Name>   
       <Version>9.0</Version> 
  </HostApplication> 
   <Addin> 
      <FriendlyName>ReviewPal</FriendlyName> 
      <Description>ReviewPal - Code review companion.</Description> 
      <AboutBoxDetails>For more information about </AboutBoxDetails> 
      <AboutIconData>000001000600200</AboutIconData> 
      <Assembly>E:\VS.Net\ReviewPal\ReviewPal\bin\ReviewPal.dll</Assembly> 
      <FullClassName>ReviewPal.Connect</FullClassName> 
      <LoadBehavior>0</LoadBehavior> 
      <CommandPreload>0</CommandPreload> 
      <CommandLineSafe>0</CommandLineSafe> 
   </Addin> 
</Extensibility>

The important tag here is the <Assembly> which contains the DLL location for the Add-In. For usage only; this could be set to the release version of the DLL either from the same directory where .AddIn file resides or from an installation folder. If you are to develop the Add-In or for debugging, this can be directed to the debug folder of the DLL.

The starting point of a Visual Studio plug-in is the "Connect" class which implements the two interfaces "IDTExtensibility2" and "IDTCommandTarget". This class is auto generated initially when you create a project with the template "Visual Studio Add-In" under "Other project types --> Extensibility". Then the key point of change is required on the "OnConnection" method of the "Connect" class.

public void OnConnection(object application, 
	ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
            visualStudioInstance = (DTE2)application;
  _addInInstance = (AddIn)addInInst;
  try
  {
    object programmableObject = null;
    String guidstr = "{858C3FCD-8B39-4540-A592-F31C1520B174}";
    EnvDTE80.Windows2 windows2 = (EnvDTE80.Windows2)visualStudioInstance.Windows;
    System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
    _windowToolWindow = windows2.CreateToolWindow2
	(_addInInstance, asm.Location, "ReviewPal.UI.ReviewWindow", "Review List",
 	guidstr, ref programmableObject);
    _windowToolWindow.Visible = true;
    ReviewWindow rCommentControl = (ReviewWindow)_windowToolWindow.Object;
    rCommentControl.VisualStudioInstance = visualStudioInstance;
  }
  catch (Exception ex)
  {
    Utils.HandleException(ex);
  }
}

We gain the great power of VS extensibility here with a reference to the Visual Studio instance, which we assign as a reference object within our plug-in (visualStudioInstance variable in the code), so that we get to access the IDE and control it. And then we load the UI elements implemented as "ReviewPal.UI.ReviewWindow". Notice that we load our custom UI elements through the "windows2.CreateToolWindow2" method, which creates a window within the IDE same like other in-built Visual Studio windows like the Solution Explorer or Task List. This way we inherently gain all the behaviors of the typical VS IDE windows like docking, floating, etc.

Once we have this setup, it becomes much like developing a Windows Forms application, which means you can do anything that a windows forms application can do, interacting with the IDE as and when required. So what I have done here is, provide a list of Reviews as in a grid control and user populates it with review comments. When adding a new review comment, we can get the current IDE properties as follows through the "VisualStudioInstance" reference we assigned in the initial OnConnecttion method.

TextSelection textSelection = 
	(TextSelection)VisualStudioInstance.ActiveDocument.Selection; 
int line = textSelection.CurrentLine; 
int col = textSelection.CurrentColumn; 
string file = VisualStudioInstance.ActiveDocument.Name; 
string project = VisualStudioInstance.ActiveDocument.ProjectItem.ContainingProject.Name;

With the Plug-in enabled on Visual Studio 2008 solution, you can navigate through the source code and add review comments for the code, which will be saved into an XML document when you click save (for which I have chosen XML serialization for easy implementation). And you can pass the review comments (the saved file) to the owner of the code in whatever way is preferred (may be through SVN). Then the owner of the code needs to load the review file using the same plug-in, and he can easily navigate to the code locations to address them. The data currently gathered during a review looks like below:

Class diagram of data colleced at a review

One thing to note about the Solution items hierarchy in Visual Studio is as follows:

VisualStudioInstance.Solution
--Project
----ProjectItems
------ProjectItem
------SubProject

When navigating through the solution for searching location (implementation of the ReviewPal.Common.ScanForProjectItems method), first we need to iterate through the Project s in the Solution, then ProjectItems in the projects. ProjectItem could have inner ProjectItems (in case of project items having multiple items like for an ASP.NET page with three items of .aspx, .aspx.cs, designer.cs) or it could have SubProject or nothing inner. So when searching for items, it's implemented in a recursive way to handle this.

With a little effort on XSLT, the XML can be made friendly for the users without the plug-in, Example: Click here.

Sample Image - maximum width is 600 pixels

Points of Interest

Writing plug-ins for Visual Studio was interesting but there's not much documentation, at least it's not easy to find.
Visual Studio 2005 Automation Samples is a good starting point.

So anyone can use this plug-in as a sample to start writing Visual Studio plug-ins. As a fan of Jetbrains Resharper, I tried developing plug-ins with Resharper, and also checked out DX Core, but both seemed to have less documentation to get it going, and at last I thought why should I rely on another third-party library to implement this type of a simple (but very useful :)) plug-in.

History

  • v .1.0.1 ... This is the initial version and I'll be updating ... may be with your valuable comments (when I some find time)

License

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

About the Author

Chathuranga K.W.
Technical Lead Zone24x7
Sri Lanka Sri Lanka
Member
Working on .Net stuff, over five years of experience mainly on Web development.
MCP,MCAD,MCSD

http://chathurangaw.blogspot.com/

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   
QuestionVisual Studio 2010 Support?memberFrancisco Manuel Suárez Grueso26 Nov '10 - 23:55 
Hello,
 

Does ReviewPal support for Visual Studio 2010?
 

Thank you very much.
AnswerRe: Visual Studio 2010 Support?memberChathuranga K.W.30 Dec '10 - 1:46 
It's being a long time, but finally I updated it with some good enhancements.
Check it out @ ReviewPal
I'll be releasing a Visual Studio 2010 Extension soon
AnswerRe: Visual Studio 2010 Support?memberChathuranga K.W.30 Jan '11 - 17:54 
I have added added to the Visual Studio Gallery @ http://visualstudiogallery.msdn.microsoft.com/d1e40c49-da36-42a5-8d5a-4ebe1feabbc9
as well as open sourced @ http://reviewpal.codeplex.com/
GeneralMy vote of 5memberMember 14304117 Sep '10 - 20:15 
the best add-in example in code project and website. Such clean and nice. great job.
GeneralRe: My vote of 5memberChathuranga K.W.30 Dec '10 - 1:46 
It's being a long time, but finally I updated it with some good enhancements.
Check it out @ ReviewPal
I'll be releasing a Visual Studio 2010 Extension soon
GeneralRe: My vote of 5memberChathuranga K.W.30 Jan '11 - 17:55 
I have added added to the Visual Studio Gallery @ <a href="http://visualstudiogallery.msdn.microsoft.com/d1e40c49-da36-42a5-8d5a-4ebe1feabbc9">http://visualstudiogallery.msdn.microsoft.com/d1e40c49-da36-42a5-8d5a-4ebe1feabbc9</a>
as well as open sourced @ <a href="http://reviewpal.codeplex.com/">http://reviewpal.codeplex.com/</a>
GeneralI am not able to usederstand how to use this addins in existing projectmemberkeyur soni4 May '10 - 1:43 
Please explain clearly how to use this addins.
GeneralRe: I am not able to usederstand how to use this addins in existing projectmemberChathuranga K.W.10 Jun '10 - 19:47 
In Short, once u copy the build files (dll etc) to the Visual Studio Add-In folder and restart Visual Studio IDE, you'll see a Add-in called Review Pal available in Tool -> Add-in Manager. load it to use the plugin.
GeneralRe: I am not able to usederstand how to use this addins in existing projectmemberChathuranga K.W.30 Dec '10 - 1:45 
It's being a long time, but finally I updated it with some good enhancements.
Check it out @ ReviewPal
I'll be releasing a Visual Studio 2010 Extension soon
GeneralMy vote of 1memberkeyur soni4 May '10 - 1:42 
Not clear description how to use this addins.... very poor
GeneralRe: My vote of 1memberChathuranga K.W.30 Dec '10 - 1:45 
It's being a long time, but finally I updated it with some good enhancements.
Check it out @ ReviewPal
I'll be releasing a Visual Studio 2010 Extension soon
GeneralEnhance the add-inmemberseagle01283 Dec '09 - 0:51 
Hey man, I improved this tool and sent a email to you (chathurangaw@gmail.com, is it right?). Please check your email Smile | :)
GeneralRe: Enhance the add-inmemberChathuranga K.W.30 Dec '10 - 1:44 
Hey,
It's being a long time, but finally I updated it with some good enhancements.
Check it out @ ReviewPal
I'll be releasing a Visual Studio 2010 Extension soon
GeneralRe: Enhance the add-inmemberChathuranga K.W.30 Jan '11 - 17:57 
I have added added to the Visual Studio Gallery @ http://visualstudiogallery.msdn.microsoft.com/d1e40c49-da36-42a5-8d5a-4ebe1feabbc9
as well as open sourced @ http://reviewpal.codeplex.com/
GeneralIs it safe to to develop a plugginmemberjohan s max22 Nov '09 - 22:16 
Is it safe to develop a pluggin ?
I need a clarification. Why ?
1. plugin modify the visual studio itself
which make me question about it's (visual studio) stability.
I am not a master programmer.
 
2. your article doesn't cover how to rollback to previous
situation. Just in case something bad happen.
Don't want to interrupt my other projects
 
Thank you
GeneralRe: Is it safe to to develop a plugginmemberChathuranga K.W.22 Nov '09 - 22:28 
Actually you dont need to worry much about visual studio plug-ins Smile | :) .
 
1.It doesn't really modify Visual Studio, but loads the plug-in dll on top of it. There could be issues like memory consumption issues if the plug-in is not properly developed. But hey, it can do all that if you have it loaded. You can always unload the plug-in from Tools -> Add-In Manager.
 
2.Rollback to previous situation only require deleting the .dll file and the Add-in configuration file from the Addins directory, as I have mentioned in the steps to user the code.
Try it out Thumbs Up | :thumbsup:
GeneralAnother suggestionmemberGlimmerMan10 Nov '09 - 4:57 
Double click row and open file to the locate i.e. if the line is 15 in mainform.vb then open mainform.vb and go to line 15.
 
Thanks again for your efforts Smile | :)
 
Kevin S. Gallagher
Programming is an art form that fights back

GeneralRe: Another suggestionmemberChathuranga K.W.30 Dec '10 - 1:44 
It's being a long time, but finally I updated it with some good enhancements.
Check it out @ ReviewPal
I'll be releasing a Visual Studio 2010 Extension soon
GeneralRe: Another suggestionmemberChathuranga K.W.30 Jan '11 - 17:59 
I have added added to the Visual Studio Gallery @ http://visualstudiogallery.msdn.microsoft.com/d1e40c49-da36-42a5-8d5a-4ebe1feabbc9
as well as open sourced @ http://reviewpal.codeplex.com/
GeneralGreat job! Features suggestionsmemberMember 44222629 Nov '09 - 7:57 
This plug-in is very handy.
 
Here are some questions/feature suggestions:
 
- How do you delete an item? Right now you can do that by editing the xml.
- If it is possible, it would be nice to include the name of the function where the code you are reviewing is in.
- When I click on an item to go to the reviewed code I get a "Project item not found" dialog box, but it does jump to the appropriate line.
- A new status for an item could be "Performed" and then "Verified/Closed"
 
I've tried it in VS 2008 professional with C++ code.
 
Regards
GeneralRe: Great job! Features suggestionsmemberChathuranga K.W.10 Nov '09 - 4:50 
I'll consider your suggestions in the next update for sure.
It's really encouraging to see the community feedback.
Thanks.
GeneralRe: Great job! Features suggestionsmemberseagle012813 Dec '09 - 23:48 
I've implement the features and sent codes to author. Hope he will update.
GeneralRe: Great job! Features suggestionsmemberChathuranga K.W.14 Dec '09 - 3:33 
Actually I have sent the update to CodeProject days back, but no update yet. Do any guys know about a way to update, other than sending an email with update to submit@codeproject.com ?
GeneralRe: Great job! Features suggestionsmemberseagle012816 Dec '09 - 6:34 
Couldn't you update online? I don't know honestly
GeneralRe: Great job! Features suggestionsmemberChathuranga K.W.30 Dec '10 - 1:43 
It's being a long time, but finally I updated it with some good enhancements.
Check it out @ ReviewPal
I'll be releasing a Visual Studio 2010 Extension soon
GeneralRe: Great job! Features suggestionsmemberseagle012830 Dec '10 - 1:47 
Oh, thanks very much! Laugh | :laugh:
GeneralRe: Great job! Features suggestionsmemberChathuranga K.W.30 Jan '11 - 18:01 
I have added added to the Visual Studio Gallery @ http://visualstudiogallery.msdn.microsoft.com/d1e40c49-da36-42a5-8d5a-4ebe1feabbc9
as well as open sourced @ http://reviewpal.codeplex.com/
GeneralSuggestionsmemberGlimmerMan9 Nov '09 - 3:47 
First off thanks for sharing.Thumbs Up | :thumbsup:
 
In regards to “how to active,” I think that loading from the add-in manager is acceptable but would be nice to expose a command to place a menu item or button within the IDE for activation.
 
There should be a method to remove rows/entries from the XML within your add-in dialog as someone might enter a row by mistake. Granted this is easy enough for anyone with XML experience to do in notepad yet there may be some that do not.
 
Double clicking on a row gives a very generic error message “Object reference not set to an instance of an object.ReviewPal.” I have not looked at the code but I am sure you might check for an object that is nothing/null. Might I suggest that a double click (or pressing ENTER) on a row with data brings up the edit dialog?
 
If a row is entered and the form name is form1.vb then later the form is renamed your logic is not picking up the new name. Again anyone with XML knowledge can adjust this in the source file but a more elegant solution would be to simply have a editable field/text box for the file name.
 
Kevin S. Gallagher
Programming is an art form that fights back

GeneralRe: SuggestionsmemberChathuranga K.W.10 Nov '09 - 4:48 
Handling the file rename would be little tricky. Other scenarios could be those little buggy areas I'll have to revisit. I'll check them out in the next update
Thanks for the feedback
GeneralRe: SuggestionsmemberGlimmerMan10 Nov '09 - 4:51 
I agree in regards to file rename. I do not think it's that big of a deal but was worth mentioning. For me I would simply edit the XML in notepad.
 
Kevin S. Gallagher
Programming is an art form that fights back

GeneralRe: SuggestionsmemberChathuranga K.W.30 Dec '10 - 1:42 
It's being a long time, but finally I updated it with some good enhancements.
Check it out @ ReviewPal
I'll be releasing a Visual Studio 2010 Extension soon
QuestionHow exactly to activate?memberMember 39622089 Nov '09 - 1:19 
I get the window once, when I enable the add-in from the add-in manager, after that, I cannot find any reference to it, and thus, I can't start reviewing.
 
To get back to the same window, I have to set startup = disabled in add-in manager, restart vs, then enable it to bring the window up. What am I missing? Smile | :)
AnswerRe: How exactly to activate?memberChathuranga K.W.9 Nov '09 - 1:29 
Actually that's something I have to work on. Normally I don't have the plug-in set to load at startup and I only load it when I want the plug-in. I'll try to find some time to update this. Hope you can try out the plug-in knowing this constrain.
Thanks for the feedback Smile | :)
GeneralRe: How exactly to activate?memberMember 39622089 Nov '09 - 1:34 
Fair enough, but how do you activate it?
The ideal thing would be to have a button and/or a keyboard shortcut one could configure for it. Right now, the moment I close the window, I have to re-start visual studio again to bring it back.
 
Other than that, it's looking very handy!
 
What I am missing is:
- ability to just email a review to a developer (requires developer list management)
- Filter by to sort out i.e. all pending reviews by a particular developer, state, or other column
GeneralRe: How exactly to activate?memberChathuranga K.W.9 Nov '09 - 1:50 
The way I load unload it is through Tools -> Add-In Manager, so that I don't have to restart VS IDE (just a workaround for now )
feature to email the review is a nice idea, just that I thought it should go into the source control, so that it's shared through the same CMS. Thinking that the review is also important as the source code it self. Anyway it's a good suggestion.
Specifying the responsible developer is also a good point.
I'll consider these in the next update.Thanks for the feedback.
GeneralRe: How exactly to activate?memberMcCarter1 Jun '10 - 4:48 
Chathuranga,
 
This is a great plug-in, thank you very much for making it available to the community.
 
I have two suggestions:
 
1. Open source it on Code Plex so that those wonderful people that are making
code changes can more easily update the source.
 
2. Add a menu item under the "View" menu to bring back the window; I just had seven code reviewers install your tool so we could review a bunch of code, only to discover that there's no easy way to view the window!
 
Thank you very much again for all your hard work.
 
Robert
GeneralRe: How exactly to activate?memberChathuranga K.W.30 Dec '10 - 1:41 
It's being a long time, but finally I updated it with some good enhancements.
Check it out @ ReviewPal
GeneralMissing Filesmemberbrackettm5 Nov '09 - 3:24 
Missing UITests project and ReviewPal - ForTesting.AddIn from source download....
GeneralRe: Missing FilesmemberChathuranga K.W.5 Nov '09 - 3:52 
Actually the UITests project is not required for getting this going.This was just a test project I used for testing the UI controls independently.So you can safely remove it from the solution file.
About the ReviewPal - ForTesting.AddIn, it's actually not part of the project but just a linked file. This links to the .AddIn file located in the Visual Studio with the Assembly (.dll) directed towards the .ddll in the debug folder. Basically this is the one used when you debug the Add-In project. Hope this info helps you to understand why they are missing.. Smile | :)
GeneralImages are missingmemberAdrian Cole4 Nov '09 - 13:37 
I'm getting a 404 error for all images.
 
while (e) { Coyote(); }

GeneralRe: Images are missingmemberChathuranga K.W.5 Nov '09 - 2:06 
I'm seeing the images fine, can't think why it doesn't load for you Sniff | :^)
GeneralRe: Images are missingmemberAdrian Cole5 Nov '09 - 6:52 
Yup, they're there now.
 
while (e) { Coyote(); }

QuestionDownloadsmemberSopraPol4 Nov '09 - 0:53 
Anyone else getting 0 bytes downloads? Confused | :confused:
AnswerRe: DownloadsmemberChathuranga K.W.4 Nov '09 - 1:59 
Just now fixed the download link issue. Extremely sorry about it
GeneralRe: DownloadsmemberSopraPol4 Nov '09 - 2:55 
Great, thanks!
GeneralRe: DownloadsmemberChathuranga K.W.30 Jan '11 - 18:02 
I have added added to the Visual Studio Gallery @ http://visualstudiogallery.msdn.microsoft.com/d1e40c49-da36-42a5-8d5a-4ebe1feabbc9
as well as open sourced @ http://reviewpal.codeplex.com/

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 4 Nov 2009
Article Copyright 2009 by Chathuranga K.W.
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid