First Steps with ReSharper
ReSharper is ready to use right after installation. When you run Visual Studio after installation of ReSharper, you need to specify your license information and then get started.
For new users, ReSharper offers a 30-day free evaluation period. During this period, you can enjoy full functionality of the product and decide whether it suits your needs. The evaluation period can be paused and resumed with the Pause/Resume Evaluation button in the License Information dialog. During the evaluation period you will be able to see how many days are left.
This topic will help you quickly get started with ReSharper, learn how and where to find its commands, and get familiar with its most frequently used features.
In this topic:
- The first step
- Looking around
- Navigating and searching
- Coding in the editor
- The power of Alt+Enter
- Refactoring code
- Generating code
- Code style matters
- What's next
The first step
ReSharper is a keyboard-centric product. Most of its actions have default keyboard shortcuts and if necessary, you can assign a custom shortcut to any of its commands.
Therefore, right when ReSharper is ready, it prompts you to choose one of the two default keyboard shortcut schemes:
For more information, see Configuring Keyboard Shortcuts
When ReSharper is installed in Visual Studio, you will see the following changes:
- The ReSharper menu that appears in Visual Studio menu bar, contains all commands except those that are only available in context, e.g. context actions or quick-fixes. Note that the Cover and Profile submenus only appear if JetBrains dotCover and JetBrains dotTrace are installed together with ReSharper.
- A number of tool windows that appear after specific commands. All ReSharper tool windows are also available in the menu.
- ReSharper's commands are available in the context menu of the editor, Solution Explorer and other Visual Studio windows.
Note that by default, ReSharper also hides overridden Visual Studio items (e.g. refactoring and navigation commands) in these menus. If you want to preserve the original Visual Studio menu items, clear the Hide overridden Visual Studio menu items check box on the page of ReSharper options.
- ReSharper page in Visual Studio options that allows you to suspend and resume ReSharper at any time. Normally, you do not need to do this. However, if you experience performance problems when working with large solutions, suspending ReSharper may help improve the performance.
- A lot of changes in the editor and the status bar:
- Status indicator that helps you to see at once whether the current file has errors or warnings.
- A fix pop-up that appears for non-imported types. It is enough to press Alt+Enter or click on this pop-up and ReSharper will add the missing directive for all types in the file. For more information, see Importing Missing Namespaces.
- A low-priority code issue (in this case, a suggestion related to an unused public member) is greyed out.
- A medium-priority code issue (in this case, a warning about a symbol name that does not fit with the naming style) is highlighted with a blue curly underline.
- A marker corresponding to the suggestion issue (3) is displayed on the marker bar.
- A marker corresponding to the error issue (8) is displayed on the marker bar.
- An action indicator that appears to the left of the caret position if ReSharper has anything to suggest there.
- A high-priority code issues (in this case, errors related to an unresolved symbol and an incorrect return type) are highlighted with red text and red curly underline.
- A marker corresponding to the warning issue (4) is displayed on the marker bar.
- The action list, which opens by pressing Alt+Enter or clicking the action indicator (7), contains a list of quick-fixes for the issue at the caret.
- A short description of the issue at the caret appears in the status bar. You can also view descriptions of code issues by hovering the mouse over highlighted code or over the issue markers on the marker bar (5,6,9)
- If the solution-wide analysis is enabled, ReSharper allows you to see even more code issues. In this example, it detects the unused public member (3) and notifies about errors in other files of your solution. You can click on the solution-wide analysis icon to explore the detected issues.
- You can also use the Quick Launch box to find and execute ReSharper commands:
Navigating and searching
ReSharper provides a lot of navigation and search features. Let's get familiar with some of them.
Jumping to declaration
Press the Ctrl key and hover the mouse over your code. You will see that all symbols defined elsewhere become underlined when in focus. You can click any symbol while holding down the Ctrl key to navigate directly to its declaration. If the symbol is defined in the current solution, ReSharper opens the corresponding file and brings the caret to the declaration. If the symbol is defined in a compiled library, ReSharper opens it according to your preferences. For more information, see Go to Declaration.
To navigate in the opposite direction, i.e. to find all places in your solution where the symbol is used, press Alt+F7. ReSharper will quickly find and display all usages of the symbol. For more information, see Find Usages.
Checking available navigation actions
Another handy navigation shortcut is Ctrl+Shift+G. When you press it on any symbol, ReSharper shows you all available navigation options: For more information, see Navigate To.
Finding anything in your solution
If you need to find anything in your solution, press Ctrl+N. The list of suggestions appears as soon as you invoke this feature and initially includes your recent files and navigated items. You can start typing to find types, symbols, files, recent edits, recent files, and recently viewed methods. For more information, see Go to Everything/Type.
Locating current file in the solution tree
When a navigation command brings you to a new file, you may want to see where it is in the Solution Explorer. Just press Shift+Alt+L and the Solution Explorer will open the scroll to the current file and highlight it. For more information, see Locating Current Document in Solution/Assembly Explorer
Coding in the editor
When you are working in the editor, a bunch of code editing helpers are at your hand. Here are a couple of them.
Code completion (IntelliSense)
ReSharper complements and extends Visual Studio's native code completion (IntelliSense) with more advanced capabilities. For example, it narrows down the list of suggestions based on your typing, automatically imports selected types and extension methods, adds parentheses when completing method names, suggests variable and field names depending on their types, and so on.
Regardless of your preference for automatic completion, you can always invoke ReSharper's code completion features explicitly either after you have typed something or even instead of typing, where any meaningful code is allowed:
- Pressing Ctrl+Shift+Space invokes the smart completion that provides more intelligent suggestions based on the expected type of the expression.
- Pressing Ctrl+Alt+Space invokes the import symbol completion that displays all types that match a given prefix regardless of what namespace they belong to, It also inserts appropriate namespace import directives to the current file if necessary.
Selecting and moving code blocks
Whenever your caret is, try pressing Ctrl+W / Ctrl+Shift+W. These shortcuts allow you to successively select a symbol, line, or block of code so that you can easily select any desired expression for copying, cutting, or moving. For more information, see Extend/Shrink Selection
If you need to move the selected code block, press Ctrl+Shift+Alt and then use the arrow keys to move the block to any allowed position. For more information, see Rearranging Code Elements
The power of Alt+Enter
Very often you will see one of many different action indicators in the left part of the editor. You can press Alt+Enter to see what ReSharper has to suggest you at the current caret position:
Here are a couple of examples:
- If you see a red bulb or a yellow bulb icon it is even recommended to press Alt+Enter because these action indicators tell you that ReSharper has detected an error or other code issue and it knows how to fix it.
- If you see a hammer icon, you can ignore it unless you want to modify code at the caret. If you want to make changes, pressing Alt+Enter may be helpful. ReSharper provides hundreds of context actions that can, for example, quickly change symbol visibility, add code that iterates over a collection, and more.
- You can also press Alt+Enter if there are no action indicators in view. In this case, you will be able to quickly find and execute any ReSharper action in scope:
ReSharper's set of refactorings by far surpasses that provided by Visual Studio, with regard to number, usability and scope of application.
It is not easy to learn and remember each of several dozens refactorings that ReSharper provides. However, you can press Ctrl+Shift+R on any symbol in your code and check out which refactorings are available here.
ReSharper can help you concentrate on non-trivial tasks by providing a lot of features for generating boilerplate code automatically. For example, you can call a non-existent method and ReSharper will create this method based on the usage, taking into account the return type and the types of parameters.
Generating type members
When your caret is anywhere within a type declaration, press Alt+Insert. In the pop-up menu that opens, you can select an item that you want to generate for the type. ReSharper can create constructors, properties, overriding members, and more. For more information, see Code Generation.
Applying code templates
When you are about to write a typical code block, such as 'for' or 'foreach' loop, a safe type cast, an assertion, etc., press Ctrl+J and choose the corresponding live template instead. For more information, see Creating Source Code Using Live Templates.
Using a similar technique, you can surround existing code blocks with typical code constructs, such as 'if...else', 'try...catch', etc. In this case, press Ctrl+Alt+J or Alt+Enter over the selection. For more information, see Surrounding Code Fragments with Templates.
Code style matters
With ReSharper, you can control the most of style aspects in your code: naming standards, formatting rules, file and type layout, file header style, and many other tiny things (such as order of modifiers or whether to use the 'var' keyword).
You can ReSharper code style features out of the box- all default values are selected based on Microsoft guidelines and numerous best practices. At the same time, each tiny aspect of code style can be changed to fit your personal or corporate preferences.
To apply code style rules, press Ctrl+Alt+F. ReSharper will prompt you to choose one of the two default code cleanup profiles: either reformat the code or apply multiple code style rules in the selected scope.
You can check out the ReSharper Workshop on GitHub. This is a Visual Studio solution that provides step by step code exercises for navigation, editing, inspections, refactoring and more.