ReSharper for VSTO
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 MS 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 with:
The default event wireups for
Shutdown events are also far too verbose - in the screenshot below,
this prefix is redundant and there is no need to wrap event wireups with new
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 code style issues, you can call the Code Cleanup action Ctrl+Alt+F. This action is configurable, letting you pick what types of issues you want to fix:
Incidentally if you 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 F2 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 the code instead - that’s not a problem, ReSharper tracks these changes. Simply press Alt+Enter while the renamed symbol is surrounded with a border and one of the 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+N to bring up the Search Everywhere dialog. Start typing
Ribbon and you’ll see the exact method in the list, together with the type, of course:
ReSharper also has a handy Navigate To menu that can be opened by pressing Ctrl+Shift+G. It’s useful when you want to navigate from a particular symbol. 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 Type (press Ctrl+N twice and start typing its CamelHumps abbreviation):
Then, with the cursor on the class name, press Ctrl+Shift+G to bring up the Navigate To menu and choose Related Files:
Now, ReSharper shows you the second part 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.