How to customize generated view classes?

Oct 5, 2012 at 8:14 AM


We are using RazorGenerator to generate view classes to be contained within the individual modules, which contain both - controller and views. We don't want to split that into 2 assemblies, as it represents logical piece of software delivered to the customer.

The problem with the generated view classes is, that it does affect code coverage really bad.

My question is - is it possible to modify (by adding some directive within the view) generated cs file, so it is decorated with ExcludeFromCodeCoverageAttribute?

I know it is possible to provide unit tests for the views as well, but our views contain no logic except simple ui rendering and we don't find much value in testing that.



Oct 5, 2012 at 4:18 PM

We add the GeneratedCode attribute to generated views. FxCop allows supressing code analysis on generated files by setting a switch (

Oct 9, 2012 at 11:49 AM


That dosn't help us much... We don't use FxCop, but built into VS test runner with code coverage settings. I didn't find any settings there to exclude classes from code coverage based on any other attribues but ExcludeFromCodeCoverage.

So, the question is still open...

Oct 9, 2012 at 4:20 PM

My bad. I read that as code analysis, hence the FxCop reference. I suppose we could have a directive that adds attributes to the generated class. 

Oct 9, 2012 at 6:08 PM

That would be awesome. I'm looking forward to see it.

Oct 24, 2012 at 2:02 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.