With dotnet/sdk#4343 recently closed we now have support for analyzers in the CLI. But there is no way to define what diagnostics should be enabled or disabled, or a way to define the severity of such diagnostics. For big .NET we have ruleset files. I suggest that you either add support for ruleset files, or, as the trend has already set, support a json file for the same thing (because xml is ugly, really, really ugly), or maybe some config on project.json itself.
You can work around that by supplying the ruleset file directly as compiler parameters in the project.json file. This also allows you to specify additional files for analyzers.
But I agree that this feels more like a workaround then a good solution.
+1. This is needed!
You can work around that by supplying the ruleset file directly as compiler parameters in the project.json file
@pdelvo Hi, how does this look in the project.json file? Would you mind pointing to where this is documented? Many thanks.
I can't find information on it either. I had to look into the cli source to find out what the option is called. An example project.json file would be:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true,
"additionalArguments": ["/ruleset:MyRuleSet.ruleset"]
},
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-23931",
"System.Runtime.Analyzers": {
"version": "1.1.0",
"type": "build"
}
},
"frameworks": {
"netstandardapp1.5": {
"imports": "dnxcore50"
}
}
}
It is possible to globally disable a warning.
I mean, the warning will be disabled for all the classes.
I include an example of project.json for this.
Does anybody know how to disable a warning for the _specified_ class, method etc ?
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true,
"nowarn": [
"CA2213"
],
"additionalArguments": ["/ruleset:MyRuleSet.ruleset"]
},
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-23931",
"System.Runtime.Analyzers": {
"version": "1.1.0",
"type": "build"
}
},
"frameworks": {
"netstandardapp1.5": {
"imports": "dnxcore50"
}
}
}
@davkean @srivatsn Is this something that we'll get for "free" once we port to csproj?
Yes the existing csc task grabs the ruleset from a property and passes to the compiler. That would work for core as well.
Given the comment by @srivatsn above, @giggio can you try the latest CLI tools from this repo and see if that works for you?
Does someone know how to specify "additionalArguments" in the new .NET Core .csproj files?
@rsuter What are you trying to pass to the compiler? We have MSBuild items/properties for nearly all compiler arguments.
@davkean In project.json we used "additionalArguments" and "/ruleset:" to specify the StyleCop ruleset, after the migration to .csproj, the rulesets are not loaded anymore.
I found the required property (for just this case):
<CodeAnalysisRuleSet>...</CodeAnalysisRuleSet>
In VS2017 I dont have suggestions when editing a .NET Core .csproj and I couldnt find documentation for this in the StyleCop docs.
By "you don't have suggestions" you mean you don't see:

Ah, now these suggestions work... no idea why. Thanks.
Most helpful comment
It is possible to globally disable a warning.
I mean, the warning will be disabled for all the classes.
I include an example of project.json for this.
Does anybody know how to disable a warning for the _specified_ class, method etc ?