Per Project Settings or How to have different naming styles for my test project
January 18th, 2012 by Hadi Hariri
One nitpick that I myself and many have had with ReSharper is not being able to have different naming styles for types based on different projects. In my code I normally name classes using CamelCase

and in my test project I use all_lowercase

Unless you add all_lowercase as a valid naming style, you’ll always end up with those squiggly lines under all your tests. And let’s admit it, it’s not a big deal but it’s annoying. #FirstWorldProblem
Say hello to my little layer
With ReSharper 6.1 we introduced the concepts of layers, which open up many new possibilities, including sharing settings on DropBox and or setting company wide standards. What you might not know is that it allows Per Project Settings too! No big deal if you didn’t know, since we currently do not support it via the User Interface so it would be hard to figure it out. However it’s pretty simple to do and I’m going to show you how.
Our goal here is to allow all_lowercase settings for classes in our test project (Tests) and not permit the same in other projects (Project). This is the sample project layout we’re going to be working with

To make this happen, we need to create specific settings for the Tests project and allow the possibility of classes being all_lowercase. That is, the Tests project needs its own DotSettings file.
Since there’s no specific button or option to add Per Project settings in the UI, this is where we need to kind of use a workaround. We need to have a Settings file for the project and then edit the options and save it to this file. There are many ways to create this new settings files. We can copy the solution one and rename it, we can export the current settings, we can mount a new layer and have ReSharper create it for us, etc.
We’re going to use this last method. Why? Because since ReSharper mounts it when it creates the file, it will allow us to edit the settings too.
1. With the Solution open, click on Manage Options under ReSharper
2. Under This Computer, click on the Add Layer icon (on the right) and select Create Settings File

3. Save the file to the Tests project folder, in our case that would be under SolutionDir\Tests and name it (and here’s the important part) Tests.csproj.DotSettings. That is, it should be named with the ProjectName, followed by csproj or vbproj based on the type of project and with the extension DotSettings.
4. Now that we have the settings file mounted, we need to change the required settings, which in our case is to allow classes to have all_lowercase (this obviously works for other settings too). As such, double-click the recently mounted file or right click and click on Edit

5. The Options dialog comes up. We want to edit the naming styles

Modify any other settings you wish at this point and once done, hit Save on the Options dialog.

At this point, we can remove the mounted settings as its not required for it to actually work. We can also leave it in order to easily access the settings for the project in the future. If you do leave it, make sure you uncheck the checkbox so that settings are not applied to the entire solution.
[Recommendation: If you decide to leave the settings mounted, mount these under Solution Shared or Solution Personal as opposed to This Computer so that you don’t end up with a long list of different settings files]
As soon as we hit Save, the new settings automatically are picked up by ReSharper and take effect. We can now see that the naming style no longer appears incorrect under the Tests project

and if we try and use the same style in the actual Project we do get the warning

The UI will come
Once you do this once, you can pretty much copy the same file over to your different projects and rename it to match the project name. In one of the next versions of ReSharper we will provide a more intuitive UI (or should we say we’ll provide an actual UI) for this. For now however, I think this minor hack will make a few people happy!
Tags: ReSharper, ReSharper 6, ReSharper 6.1, ReSharper settings

January 18th, 2012 at 10:02 pm
It’s not that our company wants per-project settings, it’s that we want per-project-type settings. Unit test projects have one convention, client application projects another, and web projects a third. This is a step in the right direction.
January 19th, 2012 at 12:58 am
Does this apply to solutions? Do you automatically read and apply a “.sln.DotSettings” if there is one?
January 19th, 2012 at 10:34 am
@Tim,
That’s how it works by default now. When you save settings for solution, it saves them as a .sln.DotSettings file. That part is supported in the UI.
January 19th, 2012 at 5:56 pm
That’s a useful feature Hariri, thanks for that.
I’ve just come across an alternative method that targets tests:
http://atombrenner.blogspot.com/2010/07/how-to-change-resharper-naming-style.html
I just wish there was a naming style of SomeTitleCase_MoreTitleCase or even SomeTitleCase_MoreTitleCase_MoreTitleCase.
January 19th, 2012 at 6:11 pm
@Tony
Yep. That works too!
January 19th, 2012 at 6:12 pm
@Hadi, apologies for addressing you by your last name.
January 20th, 2012 at 12:07 am
@Hadi,
Thanks. Actually I mis-spoke. I’m actually looking for multi-solution settings. It sounds like solution-level is automatic as you described, but what about this hierarchy:
/Root
/Root/Solution1/Solution1.sln
/Root/Solution2/Solution2.sln
If I want to apply settings to both, I’d like be able to place a *.DotSettings file in either /Root or even the directory above it, and have it apply to both solutions. Is this possible? Can it be hooked automatically like this is for csproj files?
Thanks!
January 20th, 2012 at 10:02 am
Is it possible to set such rule as Tony suggested: SomeTitleCase_MoreTitleCase or SomeTitleCase_MoreTitleCase_MoreTitleCase?
January 20th, 2012 at 11:56 am
@Tim,
Out of the box this functionality as far as I’m aware is not currently supported. I will check though and get back to you if it is.
January 20th, 2012 at 5:08 pm
@TonyHunt, +1 for the suggestion of SomeTitleCase_MoreTitleCase_MoreTitleCase. We use that in our tests — “ThisMethod_InTheseCircumstances_ShouldDoThis”. Currently we just tell ReSharper not to check method names at all, but that’s not a great workaround.
Have you written a YouTrack ticket for adding a TitleCase_WithUnderscores option? If so, post a link here and I’d be happy to vote for it. If you haven’t written a ticket, perhaps I should. (Heck, for all I know, maybe I already have…)
January 20th, 2012 at 7:20 pm
@Joe, Tony, Serg,
Log it please, give me the ID and I’ll see if we can try and get it scheduled.
January 20th, 2012 at 10:18 pm
@Hadi, an alternative I just thought of: Can a .sln.DotSettings file just reference a team settings file by relative path? This would solve the problem by avoiding each developer having to add a top-layer UNC path team settings file, while still allowing shared settings accross solutions.