This project is read-only.

SA1633 on Visual Studio 2012 TemporaryGeneratedFiles

Sep 3, 2012 at 11:39 AM

In my Visual Studio 2012 solution i have a number of projects and associated unit test projects.

All projects are set to run stylecop (4.7.36) on build.

I have turned off analysis of designer/generated files.

The standard projects work as expected, however the unit test projects flag "SA1633: The file has no header" when stylecop is run on build.

This appears to be due to Visual Studio generating files called TemporaryGeneratedFile_<guid>.cs in the obj/release folder.

Any ideas how to prevent analysis on these files?

Sep 3, 2012 at 1:11 PM

In the settings file you can specify which files are treated as generated files:

The default is:

    <Parser ParserId="StyleCop.CSharp.CsParser">
        <CollectionProperty Name="GeneratedFileFilters">
So add a new value for your TemporaryGeneratedFile_<guid>.cs files.

Sep 3, 2012 at 1:43 PM

Thanks for the info.

I have about 30 of these files, and each ends in a different guid.

Is it possible to use a wildcard in the <Value>? If so what's the syntax for this?

Sep 3, 2012 at 2:09 PM
Edited Oct 5, 2012 at 1:56 PM
It's a regex

Sep 3, 2012 at 2:12 PM

Ah that's perfect.

All sorted now!

Thanks very much for your help!

Oct 4, 2012 at 7:10 PM

What setting did you end up using? I've tried to formulate the regex but I can't get it to work:-

<StyleCopSettings Version="105">
    <Parser ParserId="StyleCop.CSharp.CsParser">
        <CollectionProperty Name="GeneratedFileFilters">
Does that look correct?

Oct 31, 2012 at 4:23 PM

Try the following:

Oct 31, 2012 at 6:18 PM

Thanks very much @belairb.

Actually I can no longer remember where I had this problem. I must have worked around it in some other way. If the problem comes up again then I'll be sure to give that a try.

Nov 10, 2012 at 10:49 PM

@belairb I just created a new .NET 4.5 project and the problem returned. I tried your suggestion and it worked perfectly!

Thanks again.

Jul 2, 2013 at 12:41 PM
Fixed my problem with the .NET 4.5 Targeted build as well.
Apr 14, 2014 at 4:37 PM
I am facing the same problem with .NET 4.5 VS 2013. Tried the suggestions but no luck.
Apr 15, 2014 at 11:01 AM
After doing some research here are my findings. In my project I want stylecop to enforce rules on some files that meet the stylecop generated file pattern. For example like Product.Generated.cs. By default this pattern is included in GeneratedFileFilters so I have to use AnalyzeGeneratedFiles=True to force stylecop check those files. I think this is where the trouble is. From stylecop behavior it seems it doesn't bother to check GeneratedFileFilters if AnalyzeGeneratedFiles is forced. So bottom line is it seems that you can't skip specific generated pattern while enforcing the rules on others.