It would be great if there was a way to define the preferred StyleCop configuration (with stylecop.json and perhaps an accompanying ruleset file) and have it applied to every solution of an organization.
The model I'm thinking of is how ESLint works in the nodeJS world. You can define your code style preferences and package them as an npm package. Anyone can follow those rules by installing that package.
Perhaps something similar can be implemented with NuGet?
Looking into the csproj format, I see two separate moving parts:
In the ideal situation, it should be possible to point both these two elements to a NuGet package containing the common organization-wide ruleset and stylecop.json file.
Shared configurations are already possible. Approaches include:
Directory.Build.props for applying configurations to projects in subdirectoriesThanks for such a fast response! I need to spend some time studying these approaches as I'm not familiar with props files.
It worked great. I'll try to make some time to write a guide. Perhaps I'll make a PR to have it as part of the documentation of this project.
I created a PR here https://github.com/DotNetAnalyzers/StyleCopAnalyzers/pull/2644/files
Thank you for the explanation, you have saved me a lot of time @sharwell . But I am facing a problem with including a default .editorconfig in a nuget package:
I tried to add this line in Directory.Build.props the same way the stylecop.json is added
<AdditionalFiles Include="$(MSBuildThisFileDirectory).editorconfig" Link=".editorconfig" />
I noticed that a reference to the file is added to the project as it appears in the solution explorer but when i click on it, it won't open so I tried to navigate to its containing folder and it is not there. But when i copy it to the package directory C:\Users[username].nuget\packages[package_name][verion]\build it works. Is this a bug or i am doing something wrong.
But I am facing a problem with including a default .editorconfig in a nuget package
This is not currently supported. .editorconfig is a filesystem-based specification and must be placed in a specific location relative to source files or the IDE will not be able to locate it.
Does this feature related to nuget packaging or Roslyn?
Also, i am facing another issue when i try to install my nuget package in a .Net framework project "console, desktop, .." it won't work showing an error
Unable to find a version of 'StyleCop.Analyzers' that is compatible with '[MyNugetPackage] constraint: StyleCop.Analyzers (>= 1.1.0-beta006)'
but it works for .net standard or .net core projects ? Do i have to lower the version of StyleCop or what ?
Does this feature related to nuget packaging or Roslyn?
It's a Roslyn issue/limitation.
but it works for .net standard or .net core projects ? Do i have to lower the version of StyleCop or what ?
I'm not sure what the requirements are here. This seems like a question for the NuGet team since it depends on how all the individual packages were constructed, deployed, and consumed.
Most helpful comment
I created a PR here https://github.com/DotNetAnalyzers/StyleCopAnalyzers/pull/2644/files