How to set rules to throw "errors" during Build on Visual Studio?

时间:2016-07-11 19:52:14

标签: c# visual-studio

I would like to set some restrictive rules on my Visual Studio 2012.

In my case I need to during the build, if Visual Studio identify that there is some properties with the first letter in lower case, throw an error and not just a warning.

How could I configure this?

1 个答案:

答案 0 :(得分:1)

I add the StyleCop.Analysers package to my project. (https://www.nuget.org/packages/StyleCop.Analyzers/1.0.0)

I have a set of style rules in a solution wide .ruleset file( http://pastebin.com/vstb3vki) and I've modified my project file to break the build if it doesn't follow the conventions. It ensure class names, properties names are correct. Correct spacing etc.

In the build tab I also set 'Treat warnings as errors' to All.

This will give you build time checking. You can also write some unit tests to validate.

And it goes without saying to use Resharper :)