Sharing code styles in ReSharper

Have just started a new project and my first task is some Silverlight thingamajig that I’m sure I’ll go on about ad nauseum in the coming weeks. But first, let’s talk about some ReSharper settings.

My very first check-in in the code base was a ReSharper code style settings filimagee. This is a way of allowing everyone on the team uses the same settings. The documentation for this feature is here though it’s a little out of date. To the right is a screenshot from version 4.1.

This is somewhat important for me because I have some different ideas about whitespace than most people. And I don’t want to impose my will on someone else. (At least not so crudely.) Nor do I want to alter my own personal projects just because everyone else likes to have all their code scrunched up together so that parentheses and curly braces essentially take the place of spaces and you need a &*%$ Little Orphan Annie Decoder Ring to parse out the actual meaning of these god-forsa–…

Ummm…let’s just say I’m a little set in my ways and move on…

By default, your ReSharper settings are global across all projects. The two other settings are: a) Shared across the team, per solution, and b) Not shared, per solution, stored in a file.

Both are very useful in teams where developers work on more than one project, such is the case here. The other obvious example is open-source projects. Here’s a quick run-down of each.

Shared across the team, per solution

Here, the code style settings are stored in a .resharper file in the same folder as the .sln file. This is ideal for a non-intrusive way to enforce coding standards on a project. Developers download the source and go. They may not even know it’s using a shared code style.

MvcContrib uses this mechanism to enforce standards. I’m not on the new project because I’ve added .resharper files to my global SVN ignore list and I’m too lazy to change it. Plus, I’m not quite sure how it works between ReSharper 4.0 and ReSharper 4.1. I.e. is it able to manage users that use 4.0 and others that use 4.1? And what happens when one user changes the settings inadvertently? As an example, I just updated to the latest MvcContrib, opened it up, and now I have MvcContrib.4.1.resharper checked out for some reason.

So instead, we’re using the next option.

Not shared, per solution, stored in a file

With this option, you explicitly tell ReSharper where the settings are stored. It requires a little more work to set up. Unlike the previous option, the developer needs to go into the ReSharper settings and physically select this option and navigate to the file. It takes an absolute path, not a relative one.

I’m guessing that this is because the settings to tell ReSharper which option to use are stored in the .resharper file, which as I’ve mentioned, we’re not including in source control.

Both options give you the ability to set standards like naming conventions, spacing, and, theoretically, how to re-order methods, fields, and properties within your class. I say theoretically because this particular one (under Type Members Layout) seems a little eccentric. I had to import the settings from the code style file, then shut down and restart the solution for them to take. And when I make changes to this section, they aren’t always reflected in the settings file.

None of this guarantees that your code will be consistent. After all, not everyone may have ReSharper. Also, I’m pretty sure the settings to auto-format are machine specific so someone could turn them off and then you have to rely on them to do an explicit auto-format before they check in. Furthermore, it appears that formatting profiles are also machine-specific, so even if you create one that runs through all your rules, re-orders things, and otherwise cleans up when you press Ctrl+Shift+Alt+F, that won’t get propagated to anyone else’s machine.

Kyle the Styled

This entry was posted in Coding Style, ReSharper. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Kyle Baley

    Arne: ReSharper seems to override the VS settings I think. It’s not something I’ve looked at because R# has pretty much all the VS settings and then some so I never go back to look at the VS settings.

    Also, I’ve noticed that not all settings are saved in the solution-specific file. For example, formatting profiles seem to be machine-specific and are not stored in the solution-specific settings.

  • http://www.claassen.net/geek/blog Arne Claassen

    I guess i should just test this out myself, but how does this work in relation to visual studio’s own style setting? Does resharper overwrite those settings per solution when it loads the resharper settings as well, or will those settings remain out of sync?