OmniSharp / omnisharp-roslyn

OmniSharp server (HTTP, STDIO) based on Roslyn workspaces
MIT License
1.79k stars 420 forks source link

Analyzers: Is there a way to reflect the ruleset on the referenced project? #1523

Open Ronyta opened 5 years ago

Ronyta commented 5 years ago

I am not very good at English, so I apologize in advance.

env

Example

TargetProject has this method.

public int SampleMethod(int val)
{
    return 1;
}

=>problem console displays IDE0060.

...

I added this ruleset to TargetProject.

<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Custom Rulset" Description="Custom Rulset" ToolsVersion="12.0">
  <Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.Features" RuleNamespace="Microsoft.CodeAnalysis.CSharp.Features">
    <Rule Id="IDE0060" Action="None" />
  </Rules>
</RuleSet>

=>IDE0060 hides from problem console.

...

Next, I created TestProject.

dotnet new xunit -o TargetProgram.Test
dotnet add reference ..\TargetProject\TargetProject.csproj

=>When TestProject is displayed on VSCode, IDE0060 is displayed on the problem console.

Is there a way to reflect the rule set in the reference project or not analyze the reference project?

savpek commented 5 years ago

I am not 100% sure but i think only solution for that is to share ruleset between projects, like move it to upper directory and reference same ruleset file from referenced projects.

Ronyta commented 5 years ago

Thank you for answering!

But it did not solve....

I set up a Ruleset file with the same contents as TargetProject in TestProject. The specific source on TestProject side is as the rule, but the source on TargetProject side is the default rule.

The path has been changed to handle one Ruleset file.

<CodeAnalysisRuleSet>../TargetProject/custom.ruleset</CodeAnalysisRuleSet>

However, this was the same as share rulesets, and I did not solve it.