ReSharper for VSTO

Skip to end of metadata
Go to start of metadata

Redirection Notice

Icon

One of the myriad project templates shipped with Visual Studio concerns the development of Microsoft Office add-ins. These add-ins can be developed using .NET languages such as C# or VB, and are consequently supported directly by ReSharper. Let’s take a look at the way in which development of a PowerPoint add-in can be improved using ReSharper’s features.

It all starts with choosing a template for your add-in. Despite the fact that Office templates are separated by version, in practice Office 2010 and 2013 projects are mutually compatible, so a 2010 project will run just fine on 2013. The selection here only affects your debugging possibilities, i.e. the version you choose will cause the project to be debuggable only on that version of Office.

As is often the case, the default project template adds a rather large number of using statements that ReSharper can help you get rid of:

The default event wireups for Startup and Shutdown events are also far too verbose -- in the screenshot below, the this. prefix is redundant and there is no need to wrap event wireups with new System.EventHandler:

Instead of fixing these problems one by one, ReSharper offers you several options. First, each of the types of issue can be fixed in a particular scope -- in a file, project or the whole solution:

Alternatively, if you want to fix different types of issue, you can call the Code Cleanup action. This action is configurable, letting you pick what types of issues you want to fix:

Incidentally if you, like me, think that regions are bad, you might want to remove those #region directives around the InternalStartup() method. ReSharper gives you a context action to do this instantly:

Now, you probably want to add your own functionality to the add-in. You can start adding your class right in the add-in file if you want to, because when you’re done, ReSharper gives you a context action to move the class into a separate file:

Now, it’s almost certain that you will be subscribing to various events, say the events generated by button presses in the ribbon. You don’t have to stick to the underscore-based naming conventions -- simply press Ctrl+R,R to rename the method. ReSharper asks you for how you want the handler renamed, and even gives suggestions:

Of course if, for some reason, you end up renaming the method in code instead -- that’s not a problem, ReSharper tracks these changes. Simply press Alt+Enter and one of the context actions will offer to apply that same Rename refactoring:

Navigation with ReSharper is also a breeze. For example, to find the location in code when the ribbon loads, you can simply press Ctrl+T to bring up the Go to Everything dialog. Type in Ribbon and you’ll see the exact method in a list, together with the type, of course:

ReSharper also has a handy Navigate To menu that can be opened by pressing Alt+`. It’s useful when you want to navigate from a particular element. For example, say you want to look into the generated methods for ThisAddIn. What you do is, first of all, find it with Go to Everything:

Then, with the cursor on the class name, press Alt+` to bring up the Navigate To menu and choose Implementation:

Now, ReSharper shows you the two parts of this partial class. You simply pick the file to which to navigate:

Hopefully this guide has shown you some of the ways that ReSharper can help with developing VSTO add-ins. Good luck!