Thursday, 26 June 2008

Beautifying .NET Code

Every company I have worked in has had their own coding guidance and styling and where non existed I was involved in the creation of one.  Having guidance on how code will be created and styled is very important as it reduces the time it take for each developer to move from task to task especially when many developers are maintaining the same class.

The only issue with code guidance and styling it is hard to enforce, especially in smaller teams with very limited resources, what is needed is an application which could enforce the chosen styling.

In comes StyleCop and NArrange;


Microsoft Source Analysis a.k.a StyleCop is another one of Microsoft's internal tools released to the public, it uses a number of predefined rules which outline how the code should be styled.

When you include this tool as part of your build process it raises error or warnings informing you how your code fails the predefined rules.

As you can expect from Microsoft this tool is very good however been warned there are many rules and some of them very different from the public guidance that Microsoft gives!  This tool will only work on C# code, because Microsoft believe the VB.NET does enough self formatting.

A new version is already in development which will include the ability to easily create new rules and automatically format code.

For more information and to download visit MSDN Code Gallery


NArrange is not a Microsoft product but is the community effort to create a similar tool.  This tool is very much like StyleCop and will tell you how your code does not meet predefined styles and guidance however this tool will reformat your code to meet the styling and will do all this for C# and VB.NET.

Currently NArrange is only in Beta but the team are regularly releasing versions and they are on version 0.2.4.

To find out more and download visit SourceForge.NET

Or read the review at