Use StyleCop
Answered
Hello! I have some questions:
1. Is is possible to use StyleCop.Analyzers is Unity Rider project? Or unity project is not .NET core project?
2. Where should i put Settings.StyleCop file to override standart rules? And how can i apply this rule to format code?
Please sign in to leave a comment.
Hello!
1. Yes, it is possible to add Roslyn analyzers to a Unity project. However, it is not super easy, as Unity regenerates csproj files, and reference to Analyzer will be lost if you add it there. Please check out this how-to for a workaround
2. StyleCop.Analyzers package doesn't support Setting.StyleCop. You can use a .ruleset file instead. Put it hear the dll with analyzers as suggested in the workaround.
Your question was answered a year ago, but if anyone find this by googling later. I think a better solution would be to add project configuration in Directory.Build.props, this is where you can set your analyzer references, C# language version, link your stylecop.json and analyzers.ruleset.
In your project root folder:
Directory.Build.props
This will set the above configuration to any csproj in your solution.