Orchard CMS Quick Tip–Curling up with Orchard, or brace line breaks without ReSharper

Orchard CMS requires that all commits to the core use the JavaScript style curly brace positioning, where the opening brace is on the same line as the method signature. If you use ReSharper then it comes with an automatic .resharper file that applies this out-of-the-box but non-users can still get this functionality with plain vanilla Visual Studio.

This isn’t a post against ReSharper at all, I think its great, but its not-free so not every developer has it. If you are wanting to contribute to the Orchard core, write a blog post about Orchard with code or just have your custom modules look like they are part of the rest of the code this quick tip will let you get the brace positions the same.

What’s the difference?

Lets take a simple example. A normal install of Visual Studio would format a piece of code like this:

Update – Orchard also supports the free Rebracer extension

It was pointed out to me (#1, #2) that Orchard actually also supports a free add-on which will manage the settings described below. If you’re using a version of Visual Studio that supports extensions then you should probably install this instead:

It’s a free extension that adds in support for automatically managing the settings for brace line-breaks based on the configuration values located in a rebracer.xml file.

Orchard comes with one of these in the root of the solution so you just install it and your Orchard solution will automatically pick it up, no further configuration required. The benefit of this is twofold:

Zero configuration

Your non-Orchard solutions can have their own (normal) brace line-break settings.

So unless there is some restriction with your environment it makes sense to use this.

How do I do it with pure Visual Studio settings?

It’s just a few checkboxes within the options panel:

Click Tools | Options…

Scroll down to the Text Editor node

Expand the C# node

Expand the Formatting node

Click on the New Lines node

You will see a list of options like in the image below which give you full control over when Visual Studio should put your open brace on a new line. Remove the check’s from all of the checkboxes in the “New line options for braces” section.

Click OK

When you change this setting it will change it for all of your projects, so if you switch between Orchard and non-Orchard projects you will have to come back and re-enable these settings.

Older versions of Visual Studio

You might not see these options. Some of the older versions of Visual Studio showed simplified settings by default. It seems like (in Visual Studio Community 2015 at least) that it defaults to showing all the settings now.

If you can’t follow the steps above then look for a Show all settings checkbox in the bottom corner of the Options dialog.