Using RegionErate in Visual Studio 2012

Being a creature of habit, I have been using a Visual Studio addin called RegionErate to organize my code for several years now. It works very well up to Visual Studio 2010, which doesn’t help me since I have been using VS 2012 for some time now.

These notes relate once again to my source archive file,

For RegionErate to be useful in VS 2012, I had to resort to using their commandline program, rgn.exe, that is supplied with their addin. I also copy their directory into a different path; the path I use is in this case inside of my RomyView solution’s path – but it doesn’t have to be that way.

Inside my solution directory, I created a Misc directory. This contains two directories, one that I use for my own code-analysis rule-sets; the other is for RegionErate.

The RegionErate subdirectory then contains everything from the addin, as well as my custom “code layout” XML file, which determines how their program will sort my code. To use their commandline application, all I did was create batch files in that directory, and then create my own shortcuts to those batch files on my desktop.

I have two batch files, one that formats source files, and one that removes the formatting from a source file. They are as below…


@echo off

call “%~dp0rgn” -target:”%~f1″ -layout:”%~dp0JeromeCodeLayout.xml” -noinfo –nowarn



@echo off

call “%~dp0rgn” -target:”%~f1″ -layout:”%~dp0Remove All Regions.xml” -noinfo –nowarn


To run the batch files, I just drag my code files onto them with Windows Explorer. Note that those files can’t be open in the editor while doing this.

Unfortunately it doesn’t recognize methods that use the async keyword, but that’s not such a big deal for me… It results in all async methods being at the end of the file, which is fine for me, for now…

My solution also contains a small console application called FormatCsFiles… Typically, I run this from inside the debugger. It iterates all CS files in the solution, and in parallel, adds line breaks and removes spurious ones that were added by RegionErate. This little console app of mine will not trash code file formatting, so it can be run even if the files are open, but they need to be saved first.


Addendum: Just in case anyone else should try this addin and they are not already familiar with it: My code layout XML file works around some pitfalls in the default RegionErate settings that tend to break my code… I often use pinvoke, which frequently involves declaring structs with explicit layout. The addin’s default settings will sort the members of such structs, breaking them. Breaking as in, the code will compile but crash when you try to run it. COM interfaces are similarly affected. Thus my code layout specifies not to sort structs or interfaces. (If I have a normal struct that I want sorted, I temporarily make it a class, i.e. just type the keyword class instead of struct; then sort it and change it back.)


About Jerome

I am a senior C# developer in Johannesburg, South Africa. I am also a recovering addict, who spent nearly eight years using methamphetamine. I write on my recovery blog about my lessons learned and sometimes give advice to others who have made similar mistakes, often from my viewpoint as an atheist, and I also write some C# programming articles on my programming blog.
This entry was posted in Programming and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s