On a current MVC project we’re also using the excellent T4MVC template by David Ebbo. StyleCop however, thinks the generated code is well, less than perfect – it generates some 500 warnings at the moment.
The solution to this is a simple choice between two options:
Fix the TT file to generate StyleCop compliant code, or exclude the generated T4MVC.cs class from StyleCop.
The pragmatic choice here is of course to exclude the file. But how?
I first tried to add
<ExcludeFromStyleCop>true</ExcludeFromStyleCop> to the Compile entry in the csproj file. Unfortunately that only works with builds from OUTSIDE Visual Studio.
Encapsulating the code in a region that contains the string “generated code” does the trick, but even easier is to simply put a
// <auto-generated /> comment at the top of the generated file – which of course means edit the TT file to stick it there.
Would be nice to see this included in the next release….