You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does StyleCop.Analyzers have a command-line interface? Can it be run via the msbuild command-line even? This would be especially useful on Mono, where there is no code analysis integration in Xamarin Studio.
Reacted by wk-j, Matthew Vaughan, Piotr Błażejewicz (Peter Blazejewicz), Benito PS, Noam Yogev, Kostia Vyrodov, Nace Logar, Andre Hofmeister, Robin.R, mob-sakai and 10 more
You say "needed", but actually a CLI is sometimes desirable over integration... in this case though, I have since learnt that you cannot do the static analysis without building (which is rather odd)... so I guess this is a no-go.
Need not perform every stage of the build though, I was thinking.
Would be more useful for automation, e.g. CI. With some MSBuild parameters though (I have a separate issue on that), this issue could be alleviated.
Reacted by Ivan Ribakov, Andrea Cassioli, Kostia Vyrodov, Nace Logar, Mikhail Dudin, mob-sakai, Grégoire, Emil Hjelm, Michael Hart, Andrea Di Lisio and 3 more
I agree having a proper CLI would be terrific, especially when it comes to CI.
Reacted by Alexander Regueiro, Andrea Cassioli, LMSSonos, Noam Yogev, Kostia Vyrodov, Nace Logar, Decho Dechev, Ajiemar Santiago, Casey Rojas, Mikhail Dudin and 10 more
Having a CLI utility would be amazing to work both with CI but also as git commit hook.
Reacted by Kostia Vyrodov, Decho Dechev, Ajiemar Santiago, Mikhail Dudin, mob-sakai, Daniil Samoylov, Emil Hjelm, Andrea Di Lisio, Antony Gelberg, Rafał Wrzeszcz and 1 more
Agree with the comments above.
Currently we have an issue: we are going to support legacy solution (23 project) and it has over 30K warnings. I thought, it would be super if we could run StyleCop for only those single file that were updated to fix warnings. Maybe, it's possible, but I has to integrate it with CI and I didn't find any possible solutions to lint a file, except pressing on the button 'Run StyleCop' in the VS2017.
Is this still true? I'm helping maintain client libraries / bindings in many different languages: ruby, python, js, java, kotlin, and c#. As part of this project, I'm shelling out to various language specific cli tools for linting snippets of code for documentation. Would love any pointers for running StyleCop against my c# snippets from the CLI (mac/unix)
Reacted by Kostia Vyrodov, trbs, sebastian-ulloa, naniwo, Henri Hyyryläinen, Gareth Leachman and Emil Hjelm
Hey maintainers, any thoughts about this issue after years of silence?
Reacted by Max Lerch, Emil Hjelm, Jeffrey Tremblay, Henri Hyyryläinen, Michael Hart, Maurits, Kostia Vyrodov, Andrea Di Lisio, Nikita Moshenskiy, Akın Tekeoğlu and 7 more
Reacted by Gareth Leachman, Mihai Codoban and Jermaine Sizemore
The .NET SDK now provides a general-purpose CLI for this: dotnet format, included since .NET 6. Its analyzers subcommand supports third-party Roslyn analyzers referenced by a project, including StyleCop.Analyzers.
For a project or solution referencing StyleCop.Analyzers:
# Apply supported analyzer code fixes
dotnet format analyzers .\MySolution.sln
# Check without modifying files; fail if fixes would change files
dotnet format analyzers .\MySolution.sln --verify-no-changes
# Limit the check to selected files
dotnet format analyzers .\MySolution.sln --verify-no-changes --include .\src\ChangedFile.cs
This supports CI and commit-hook workflows, but there is an important distinction: --verify-no-changes checks whether supported code fixes would change files; it is not a comprehensive gate for every analyzer diagnostic, particularly rules without code fixes. For comprehensive diagnostic enforcement, use dotnet build with the desired analyzer severities configured.
The analyzer commands still need project/reference context, so arbitrary standalone snippets are not directly covered. Also, Roslyn analysis does not inherently require emitting an assembly or performing every stage of a full build, despite the earlier discussion.
Closing as superseded by the general-purpose SDK tooling rather than planning a separate StyleCop-specific CLI. Thanks for the suggestions and discussion!
Activity
llehn commentedon Dec 17, 2017
Used as a nuget package, it integrates into the build. No CLI needed.
alexreg commentedon Dec 17, 2017
You say "needed", but actually a CLI is sometimes desirable over integration... in this case though, I have since learnt that you cannot do the static analysis without building (which is rather odd)... so I guess this is a no-go.
llehn commentedon Dec 17, 2017
Well its a roslyn based analyzer, it has to build to do its work, since roslyn is a compiler.
Out of curiousity, in what scenario would a CLI be more useful than an integration?
alexreg commentedon Dec 18, 2017
Need not perform every stage of the build though, I was thinking.
Would be more useful for automation, e.g. CI. With some MSBuild parameters though (I have a separate issue on that), this issue could be alleviated.
andreacassioli commentedon Apr 16, 2018
I agree having a proper CLI would be terrific, especially when it comes to CI.
andreacassioli commentedon Apr 27, 2018
Having a CLI utility would be amazing to work both with CI but also as git commit hook.
kostyaVyrodov commentedon Oct 30, 2018
Agree with the comments above.
Currently we have an issue: we are going to support legacy solution (23 project) and it has over 30K warnings. I thought, it would be super if we could run StyleCop for only those single file that were updated to fix warnings. Maybe, it's possible, but I has to integrate it with CI and I didn't find any possible solutions to lint a file, except pressing on the button 'Run StyleCop' in the VS2017.
cjavdev commentedon Jan 9, 2020
Is this still true? I'm helping maintain client libraries / bindings in many different languages: ruby, python, js, java, kotlin, and c#. As part of this project, I'm shelling out to various language specific cli tools for linting snippets of code for documentation. Would love any pointers for running StyleCop against my c# snippets from the CLI (mac/unix)
andreacassioli commentedon Apr 11, 2020
Hey maintainers, any thoughts about this issue after years of silence?
elachlan commentedon Aug 17, 2020
I found this but didn't get around to trying it.
https://github.com/kzu/AutoCodeFix
AArnott commentedon Oct 13, 2026
The .NET SDK now provides a general-purpose CLI for this:
dotnet format, included since .NET 6. Itsanalyzerssubcommand supports third-party Roslyn analyzers referenced by a project, including StyleCop.Analyzers.For a project or solution referencing StyleCop.Analyzers:
This supports CI and commit-hook workflows, but there is an important distinction:
--verify-no-changeschecks whether supported code fixes would change files; it is not a comprehensive gate for every analyzer diagnostic, particularly rules without code fixes. For comprehensive diagnostic enforcement, usedotnet buildwith the desired analyzer severities configured.The analyzer commands still need project/reference context, so arbitrary standalone snippets are not directly covered. Also, Roslyn analysis does not inherently require emitting an assembly or performing every stage of a full build, despite the earlier discussion.
Closing as superseded by the general-purpose SDK tooling rather than planning a separate StyleCop-specific CLI. Thanks for the suggestions and discussion!