|Table of Contents|
Over the years, we as developers form our own sets of practices about how we write code. An inevitable consequence of this is that these practices are bound to differ between development teams or even between individual developers.
It should therefore come as no surprise that one of ReSharper's goals is to accommodate these differences by providing flexible customization options. Another important point is to give a simple and flexible way of sharing the customized settings within development teams.
This guide serves as an overview of ways in which you can customize your ReSharper experience to best align it with your needs and the needs of your organization.
To get started with ReSharper customization, choose ReSharper | Options in the Visual Studio menu bar. You will be presented with the following dialog box:
The Options dialog box is split into two parts. The left-hand part presents a feature tree, letting you choose which feature you want to customize. There are the following feature categories that represent root nodes of the feature tree:
- Environment - this category includes things related to UI and the editor, Visual Studio integration, and general settings.
- Code Inspection - here you can configure features related to code analysis.
- Code Editing - in this category you will find options that define code transformations, cleanup, formatting and styles.
- Tools - this category lists settings of ReSharper tools
The right-hand part shows the actual property page for the selected feature, where various options can be set. You can always hit F1 or click on the '?' icon in the Options dialog box to study detailed descriptions of every single option on the current options page.
As soon as you change any of the options, you will see a yellow warning in the bottom of the dialog box showing you the number of unsaved changes. You have two buttons that allow you saving the changes: Save and Save To. Save just saves the settings for you while Save To lets you choose a particular setting layer where the change is saved. Normally, you will need to click Save To and use setting layers only when you want to share custom settings. To learn more about saving settings, please read this article in the JetBrains .NET Tools Blog.
In the bottom of the Options dialog box, you will also find the Manage... button, which allows managing setting layers with the Settings Layers dialog box:
We won't expand on managing settings here (to learn more on the subject, please study posts tagged ‘ReSharper settings’ in the JetBrains .NET Tools Blog), however, one button in this dialog box is directly related to our current topic - Reset All Settings - it will allow you at any point to reset all settings to their factory defaults.
Now let's go through the options pages.
In this page, you will find general options that are mostly self-explanatory, like showing tips on startup and switching icon themes. A couple of settings that may need explanations are:
- Loop selection around ends of a list allows ReSharper to loop the scrolling of popup lists if you scroll them with the keyboard arrow keys. The setting applies to all popup lists that appear for navigation and search actions as well as for code completion actions.
- Caches. ReSharper caches solution model on the file system to speed up its operations, and these options let you define where exactly. If your solution is under VCS, then you might not want caches in the solution folder, but if you work alone, solution folder might be a good choice. At any moment you can remove cached files with the Clear Caches button. Normally, you do not need to clear solution cache, but some events (e.g. sudden power off or an upgrade that skips several versions) may corrupt the cache, and that's when you need to use this button. Signals of corrupted cache may be a lot of unresolved code or absence of ReSharper inspections in some files. After clearing the cache you need to reopen your solution and wait a little while ReSharper rebuilds the cache.
Keyboard & Menus
ReSharper overrides some Visual Studio features. For example, instead of 6 native refactorings of Visual Studio, ReSharper provides more than 40. If you want these overridden commands to be replaced with corresponding ReSharper commands in context menus and toolbars, tick the Hide overridden Visual Studio menu items check box.
Some of ReSharper’s features are intended for constant use, which makes it less convenient to use the mouse. Naturally, ReSharper supports keyboard shortcuts, the only question being how you want to manage them. There are two sets of predefined shortcuts called 'keyboard schemes'. Check this reference page to learn both schemes in detail.
There are, three options related to keyboard shortcuts:
- The Visual Studio scheme will be useful for people who are already accustomed to VS shortcuts. Choosing this option will get ReSharper to add its own shortcuts in unoccupied slots, causing no conflicts. Which means you don’t have to re-learn anything.
- The setting for ReSharper 2.x or IntelliJ IDEA will be useful for two categories of people – those who have worked with ReSharper from the early days and those who also happen to work with IntelliJ IDEA. Beware – this setting overwrites several settings of Visual Studio itself, but ReSharper will hint you to resolve conflicting shortcuts as soon as you first use them.
- The None option lets you define no shortcut keys at all. This is useful if you want to selectively apply keyboard shortcuts only for the features you use frequently.
Speaking of keyboard shortcuts, ReSharper (predictably) publishes command names that can be bound to keyboard shortcuts via Visual Studio’s default interface (Tools | Customize | Keyboard). For example, here’s a shot of me assigning ReSharper’s all-important QuickFix command (used for opening up quick-fix suggestions and context actions) to the Alt+Enter key combination.
ReSharper changes your experience in the text editor with simple but addictive features, which you can configure in this page. These features include:
- Highlighting of the current line and of matching delimiters (parenthesis, brackets, braces, and quotes).
- Auto-formatting of code on semicolon and/or closing brace. Formatting rules themselves are configurable in the Code Editing | General Formatter Style and Code Editing | [language] | Formatting Style pages of ReSharper options.
- Taking into account words that compose CamelHumped names when extending/shrinking selection with Ctrl+W/Ctrl+Shift+W and moving the caret between words with Ctrl+Left/Ctrl+Right.
- Auto-insertion of closing delimiters after their opening counterparts.
Search & Navigation
Though being powerful enough, ReSharper's navigation and search features do not require much configuration. The options presented in this page are understandable at a glance, maybe except for the last one, Expand search results tree by default, which forces to expand the search result tree when it is shown in the Find Results window.
You can also configure features related to navigation to compiled code in the Tools | External Sources options page.
As you may have noticed, ReSharper comes with its own brand of IntelliSense, which provides expanded features such as, for example, the ability of using inline Live Templates (ReSharper's take on Visual Studio code snippets). To learn more how ReSharper's code completion improves upon Visual Studio IntelliSense, read this help entry.
If you are using ReSharper's IntelliSense, there's a large number of options you can configure for it.
First of all, you need to decide whether you want to use ReSharper's brand of IntelliSense or Visual Studio's. You have three options here:
The first option enables full ReSharper's IntelliSense, the second options disables it, and the third allows you to choose a set of languages where you want to use ReSharper's IntelliSense. Please note that further IntelliSense options are applicable only if you chose full or limited ReSharper's IntelliSense.
This page allows you to define how the ReSharper's IntelliSense autopopup works in various contexts of different languages. By default, the completion list automatically appears when you type any character allowed in the context; the expected item is preselected:
If you see that the guess is correct, hit Enter or any non-alphanumeric character that closes or continues the expression.
In the Autopopup page, first of all you can choose whether to enable or disable automatic appearance of the IntelliSense popup at all. If it is disabled, you can access the IntelliSense popup with various shortcuts (e.g. Ctrl+Space; for more information, see Code completion in ReSharper help). If it is enabled, you can furthter customize how and when it should be displayed.
There are two options of showing the autopopup:
- Display and preselect - when the autopopup appears, ReSharper tries to guess what are you about to type and selects it for you in the list. If the proposed item is correct, just hit Enter or any non-alphanumeric character to go on with the inserted item.
- Display but do not preselect - this option just allows the popup to show the list of available items without selection so that you could choose one manually. When you hit Enter or any non-alphanumeric character, the popup disappears and you can continue with what you've typed. However, the expected item in the popup is still highlighted with a blue frame, and if you see that the guess is correct, you can hit Ctrl+Enter to insert it.
This page has a couple of options that define when to insert the item selected in the IntelliSense popup. One non-configurable way to do it is hit the Enter key. Besides, by default you can do it with the Space or any non-alphanumeric character. In this case, the inserted item is followed by the space or the non-alphanumeric character.
If you want the Space or some non-alphanumeric characters to cancel the IntelliSense popup, you can make the corresponding configuration separately for C#, VB.NET, and the rest of the supported languages. For instance, to disable completion on Space, dot ".", colon ":", and semicolon ";", uncheck the Complete on space check-box and type ".:;" in the Do not complete on box.
The Completion Behavior page allows you to fine-tune ReSharper's IntelliSense. Some of the things you can configure are:
- Whether to include language keywords in the completion list.
- Whether to narrow down the completion list on typing
- Whether to enable or disable automatic commit for specific completions (Symbol Completion, Smart Completion, and Import Symbol Completion) in cases where there is a single possible choice in the completion list.
- Whether to automatically insert opening or both parentheses after a completion is committed.
- The Match middle of identifiers option allows the completion list display items that include the typed substring in any place. For instance, by typing
boxin a WinForm application, you will have
MessageBoxamong other items.
This page lets you define how code completion appears – whether or not it uses default VS font or that of the text editor, whether to show member signatures and summary. There is also an option to filter members with the
[EditorBrowsable] attribute – either to show only normal members (
EditorBrowsableState.Always) or to show both normal and advanced members (
The Parameter Information feature is configured as a part of ReSharper's IntelliSense though it can be used not only for typing assistance but for reviewing existing code too. The first option - Automatically show parameter info in ... milliseconds - applies only to typing method calls, the rest of the options apply to the Parameter Information popup in all situations.
Web Proxy Settings
In this page you can adjust Web proxy settings for ReSharper's Internet connection. By default, ReSharper follows your system settings and if any proxy server is defined in your system ReSharper will use it too for fetching sources from symbol servers, detecting updates, etc.
Code analysis is one of ReSharper’s central features. Throughout the analysis process, ReSharper uses the marker bar (AKA error stripe) on the left of the text editor to highlight errors and suboptimal language usage in your code.
Markers on the marker bar are colored according to the severity of the corresponding issues. If necessary, you can configure these colors in the Visual Studio options. Go to Tools | Options and then choose Environment | Fonts and Colors page. Scroll through displayed items to find ReSharper Code Analysis [Error | Warning | Suggestion] Marker on Error Stripe and select the desired foreground:
While this Visual Studio options page is open, check out other ReSharper's configurable styles and change some if needed.
The way ReSharper does analysis and, specifically, the severity it assigns to various cases of suboptimal language use, are configurable in under the Code Inspection category of ReSharper options:
Firstly, let’s take a look at the Settings page. This page governs the general settings related to code analysis - things such as whether it happens at all, and if it does happen, several further settings can be configured.
The Enable code analysis check box, as you may have guessed, determines whether code analysis happens at all. Let’s discuss the options that appear underneath it.
- The Color identifiers option, when checked, will tell ReSharper to color the text related to various inspection warnings/errors depending on severity
- The Highlight color usages option adds a colored underlines whenever color definitions (e.g.
Color.FromArgb(0, 33, 99)) are used in your code.
- The Analyze errors in whole solution turns on Solution-Wide Analysis – a feature that gets ReSharper to analyze all files in the solution. Watch out for a spinning wheel in the bottom right-hand corner of the Visual Studio window and note that this is a quite resource-consuming option, especially for large solutions.
- The Show code inspection options in action list determines whether ReSharper will let you configure analysis options right in the action list, which appears on Ctrl+Enter. This might be useful at the initial stages of ReSharper use, but may become less relevant, especially if you find that you never need to further customize inspection options.
- The option Show the “Import namespace” action popup determines whether or not you get a nice blue popup like the following for missing namespace imports:
- The Assume entry value can be null helps tuning the Value Analysis feature.
- The Edit Items to Skip button opens the Skip Files and Folders dialog box where you can configure the list of files, folders, and file masks that should be excluded from code analysis.
Not all code in a VS solution needs to be analyzed – for example, the Windows Forms designer files (Designer.cs or .vb) do not need to be analyzed. You may have some other files in your solution (for example, files generated via T4) that do not require analysis.
To tell ReSharper not to analyze them, you can use the Generated Code page to specify the elements ReSharper should ignore. Specifically, you can define:
- Individual generated files and folders that contain generated files
- File masks of generated files
- Regions within generated code (i.e., code within
This is the ‘main’ page for configuring inspections. The interface is pretty self-explanatory - for each inspection you can pick the severity that ReSharper assigns to issues found by this inspection. The options are hint, suggestion, warning, error, or an option to not show the inspection at all.
Use the Search box to quickly find code inspection items.
This page is a central location for managing Structural Search and Replace (SSR) patterns. It replaces the ReSharper | Tools | Pattern Catalog dialog box that appeared in ReSharper 5.0. You can start with this blog post to learn how to work with SSR patterns.
ReSharper uses annotations such as
[NotNull], but many developers do not want to reference a ReSharper assembly – instead, they’d rather host these attribute definitions in their own projects. The Code Inspection | Code Annotations options page allows configuring this:
The idea is simple: if you want the annotation types to be in your own solution (with your own namespaces), then you can click Copy default implementation to keyboard to get the definition of all attributes. Then, simply paste this in your project, change the namespace to the one you need, and open the Options dialog box again. You should now see your new namespace in the list of available namespaces. The Default annotation namespace combo box will also contain this new namespace.
All namespaces with checked boxes next to them will be used for annotations. As for the default annotation namespace, this actually determines which namespace will be used by default when referencing the annotation types.
Some developers prefer an underscore in front of their private variables; others do not. Both are valid choices, and they are supported in ReSharper with the concept of Naming Style. Naming styles are customizable on a per-language basis and the settings are organized similarly for each language.
Configuring Naming Styles
Let's see how to configure language settings for C# and then you can do the same for other languages: the relevant property page is under *Code Editing | [Language] | Naming Style in the feature tree.
As you can see, the property page shows us the naming rules for typical language features such as interfaces or private instance fields. Editing a naming rule is simple – you can select the corresponding line and either double-click it or, alternatively, click the Edit button. After you do so, you will be presented with a dialog box similar to the following:
Before we get to the question of why there is a list of naming conventions for this item, let’s deal with the bottom part. It’s fairly self-explanatory, really - your naming convention can include prefixes, suffixes, and a particular form of writing a variable in between. In the example above, the naming rule requires lower camel case identifier prefixed by an underscore.
Now, let’s get back up to why there’s a list control up above with options to move members up and down. First, why a list? That’s because you might have a code element that might be written in several different ways. For example, you might be writing constants in both UpperCamelCase and ALL_UPPER notations, and you don’t really want ReSharper to suggest you change those when you really don’t need to. Or, for instance, you might be used to naming your tests in a specific way that’s different from the way you name non-test code elements.
As to why there’s a list: you’ll notice that if you add more items, the top one is always in bold and marked as (Default). When ReSharper finds a code element that doesn’t conform to this rule (say, a constant that’s lowerCamelCase), it will offer to adjust the naming according to that default notation.
You may also notice the Enable inspections option when you open a naming rule for editing. Unchecking this option tells ReSharper to avoid checking naming for these types.
Sharing Naming Styles
If you work in a team, chances are that your team has common naming rules. Starting from ReSharper 6.1, you can use setting layers (briefly described in the beginning of this tutorial) to share naming styles as well as any other options. If you migrate from earlier versions, you can import your shared styles using the corresponding button on the Code Editing | Code Style Sharing page.
Besides configurable styles for symbol names, ReSharper provides configurable styles for code formatting. In contrast to naming styles, formatting styles are often enforced automatically; you may have noticed that as you type, ReSharper automatically adjusts code formatting. You can configure when to use auto-formatting in the Environment | Editor options page. Formatting styles are also applied when you expand code templates, generate code, use refactorings, etc. If you need to apply formatting styles to the existing code, use code cleanup.
General Formatting Styles
You can configure global formatting rules on the Code Editing | General Formatting Style page. Global options define how to indent multi-language files and how to use tabs in multi-line constructs when the tabs are enabled in Visual Studio options. The rest of formatting options are configured separately for each language.
Language-specific Formatting Styles
To configure language-specific formatting rules, go to Code Editing | [Language] | Formatting Style. Depending on the language there may be up to hundred different settings, which allow you to define every detail of your code layout. Formatting settings may be divided into several pages:
- Braces Layout lists settings that determine how curly braces are laid out. This feature is only available for languages that use curly braces for scoping, such as C#.
- Blank Lines lists settings that determine how many blank lines are added in particular use instances. A value of 0 implies that no blank lines are used.
- Line Breaks and Wrapping defines, predictably enough, how text is broken into lines (for example, on exceeding required document width) and the way in which it wraps around.
- Spaces lists settings that define whether or not a space is inserted in a particular instance.
- The Other page contains additional options for code formatting. For example, you can specify whether attributes are kept together like this
[A,B]or separately like this
The large number of settings, which may confuse you in the beginning, is compensated for with a very convenient editors. When you select a setting in the list, the bottom of the page shows a code sample that demonstrates how this setting affects formatting. You can play with the setting and check the changes in real time.
ReSharper provides quite a number of code generation features. The common settings for these features are available in the Code Editing | Members Generation options page.
The Generated member default body style setting applies to all generated methods and allows you to choose what to put in their bodies. The Generated property style setting defines how properties are generated for implementing and overriding members.
Also, you can opt for copying XML documentation from overridden members, wrapping generated members in regions, and annotating generated property accessors to prevent debugger from stepping into them.
Many companies have standards regarding the headers that are present in all files in the solution. Typically, headers contain such data as copyright information, the author of the file, and so on. ReSharper lets you configure the settings for file headers across the solution:
After you define these settings, you can run code cleanup in order to have these headers automatically inserted into every code file in the solution. To insert the header into new files, use file templates.
Code Cleanup is a feature that allows wholesale reformatting and cleaning up of code - whether individual files or whole projects or even solutions. Code Cleanup performs a number of operations combined in sets, such as Full Cleanup or Reformat Code. You typically choose from these sets when performing the clean-up.
For each profile, you can see the settings it applies and, naturally, ReSharper lets you define your own profiles. This is available either by clicking Edit Profiles in the Code Cleanup dialog box, or selecting Code Editing | Code Cleanup page in the Options dialog box. To learn exactly what each Code Cleanup option means and how it is configured, read this help entry.
Either way, you get presented with a configuration editor that lets you add a new profile. Now, let’s say that I want a profile that doesn’t add
var and does no code reformatting. To get this, I click Add and name my profile:
Then, I select the corresponding saving options in the bottom part of the page:
And that’s it – I can run ReSharper | Tools | Cleanup Code and begin using this profile:
Context actions are similar to refactorings in some way, but they allow simpler one-step transformations of your code. However, in some situations you might have no need for particular context actions and want them out of the action list. For example, if you are not a fan of the
var keyword, you might not appreciate ReSharper offering you to change explicit types to
var in your code.
Luckily, you have the Context Actions options pages - one common and one for each language - specifying which actions are shown and which aren’t. Simply uncheck the actions you don’t want, and you’re set!
You can use the Code Editing | Localization page to determine the way in which resources are named when you move string to resources.
Additionally, for C# you can choose whether you want to analyze verbatim strings (starting with @) in your code and make ReSharper suggest moving such strings to resources.
Type Members Layout
By default, ReSharper has a preconfigured way of laying out the members (properties, fields, nested types, etc.) of a particular type. These layout rules are applied when you run full code cleanup and can be overridden in ReSharper’s options: Code Editing | C# | Type Members Layout. (Please note that this feature is currently only available for the C# programming language.)
There are two ways of using default members layout: with or without regions. If you choose to use regions then delegates, nested types, etc. are automatically wrapped into corresponding regions. Once you choose Custom Layout, you will be presented with an editor showing XML that allows you to change the order in which type members should appear in the code file.
To learn more about fine-tuning type members layout, refer to Hadi Hariri's In-depth Look at Customizing Type Layout with ReSharper on the JetBrains .NET Tools Blog.
For C# and VB.NET, ReSharper provides a number of features that help optimizing namespace imports. There are code inspections that detect redundant namespace imports and quick-fixes that can remove such imports, there is a Code Cleanup action that can optimize namespace imports in the desired scope up to the entire solution.
The Code Editing | C# or VB.NET | Namespace Imports options pages help you configure the way ReSharper treats
using (C#) and
import (VB.NET) directives. You can:
- Choose whether to use fully qualified names or insert
- Specify namespace imports that should be never removed
- Specify namespaces that should always be imported
If you use unit tests in your solution, you may have noticed that ReSharper detects unit tests and allows running and debugging them right from the editor:
With ReSharper, you can also create test sessions and run them in parallel, run tests by categories and more. To configure unit testing features, use Tools | Unit Testing options page:
The first option - Enable Unit Testing - switches on or off all unit testing features including test detection in the editor. If it is enabled, you can configure other settings, all of which are self-explanatory.
Settings on this page apply to all supported unit testing frameworks. To modify settings that affect a particular unit testing framework, use the corresponding subpage.
In the Tools | To-do Items page of ReSharper options, you can configure the default notification items and create your own ones. To learn more about To-do items, see this blog post.
Although most of navigation and search settings are in the Environment | Search & Navigation options page, the way ReSharper navigates to compiled code is configured in the Tools | External Sources page.
The default action for navigation to compiled code is not defined but ReSharper will ask to choose one as soon as you need it.
Imagine that you call the Go to Base Symbols command from a WinForm class. In this case, the base symbol is the
System.Windows.Forms.Form class and it is defined in the .NET Framework, which is compiled and referenced from your project. If you navigate to compiled code for the first time, you will see the following dialog box:
Whatever you choose, you can change it at any moment in the Tools | External Sources options page. In fact, ReSharper's features for compiled code are enabled only if you choose the Navigation to Sources option, then ReSharper will try hard to get you to the desired destination.
Depending on what options are enabled, ReSharper can do the following:
- Use debug information in PDB files to find sources of the compiled code locally
- If local sources are not found, it will try to get them from a symbol server
- If they are still not available, it will decompile the library code
Additionally, for decompiled code you can opt for XML documentation and reordering type members according to your code style settings.
The Advanced button allows you to define folder substitution rules, which may be helpful if you have library sources locally, but the library was compiled on another computer. In this case, folder substitution rules will help you remap source folder paths from the PDB to local sources.