Stylecopanalyzers: I want to have StyleCop.Analyzers ruleset to be automatically executed for all projects in my solution including new project being added. Is there a possible way?

Created on 17 Mar 2017  路  5Comments  路  Source: DotNetAnalyzers/StyleCopAnalyzers

question

Most helpful comment

@sixlettervariables You can include it via Directory.Build.props and have it apply to many projects in subdirectories. Here is an example from Microsoft/vs-threading:

https://github.com/Microsoft/vs-threading/blob/167b298f6b99296eea89dd528437ee06555dbfbe/src/Directory.Build.props#L12-L16

All 5 comments

One suggestion is to write a custom MSBuild Task to ensure that StyleCop.Analyzers is referenced in the packages.config for all of the projects.

No automatic way that I know of, but...
1) Add a build task as suggested above
2) Create a custom project template setup the way you want it
3) Create a test case which checks that all your projects reference the analyzers you want
4) Write a script which adds missing references

+1

As I known, we can use the command shown below to run StyleCop classical without add config to new project:

msbuild /p:CustomAfterMicrosoftCSharpTargets="C:\Program Files (x86)\MSBuild\StyleCop\v4.7\StyleCop.Targets";SourceAnalysisOverrideSettingsFile="<CustomeSettingFilePath>" SomeProject.csproj

That's a harmless method to handle all project and enforce them follow a unified rule setting.

Can StyleCop Analyzer work like the StyleCop classic?

So if you have a large product (200+ projects), is the only way to use the new StyleCop is to include it as a NuGet reference in every project file?

@sixlettervariables You can include it via Directory.Build.props and have it apply to many projects in subdirectories. Here is an example from Microsoft/vs-threading:

https://github.com/Microsoft/vs-threading/blob/167b298f6b99296eea89dd528437ee06555dbfbe/src/Directory.Build.props#L12-L16

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sharwell picture sharwell  路  4Comments

wmjordan picture wmjordan  路  6Comments

DirtyPiece picture DirtyPiece  路  7Comments

Genarij picture Genarij  路  7Comments

snowjim picture snowjim  路  6Comments