dotnet / project-system

The .NET Project System for Visual Studio
MIT License
967 stars 385 forks source link

Missing rule ID entries in Ruleset Editor when opening ruleset added to new SDK style project #3573

Open mavasani opened 6 years ago

mavasani commented 6 years ago

I am using the latest internal VS dogfood build, but this repros on 15.7 as well.

Repro Steps (Repro 1):

  1. Create a new .NET framework class library project (old project system)

  2. Create an empty ruleset file named MyRules.ruleset at the root of project with following contents:

    <?xml version="1.0" encoding="utf-8"?>
    <RuleSet Name="My Rules" Description="" ToolsVersion="15.0">
    </RuleSet>
  3. Add the following property to the project file to add ruleset to the project: <CodeAnalysisRuleSet>MyRules.ruleset</CodeAnalysisRuleSet>

  4. Add a NuGet package reference to latest stable FxCopAnalyzers package

  5. Open MyRules.ruleset in the ruleset editor by executing Solution Explorer -> Project Node -> References -> Analyzers -> Open Active Ruleset

  6. Search CA1034 in the search box in the ruleset editor and confirm you get 2 entries, one for Managed Binary Analysis and one for Microsoft.CodeQuality.Analyzers: image

  7. Repeat the above steps for a new SDK style project .NET standard class library project.

Expected Searching CA1034 shows same 2 entries for SDK style project, that were seen in step 6 for old style project.

Actual No matching entries image

mavasani commented 6 years ago

Repro Steps (Repro 2):

  1. Create a new solution with one SDK style .NET standard class library project and one old style .NET framework class library project
  2. Create MyRules.ruleset (with same contents as in Repro 1) at the root of the solution and add it as an existing Solution item to this solution.
  3. Add the following property to both the project files to add same ruleset to the projects: <CodeAnalysisRuleSet>..\MyRules.ruleset</CodeAnalysisRuleSet>
  4. Add a NuGet package reference to latest stable FxCopAnalyzers package to both the projects
  5. Double click on the MyRules.ruleset in the solution items to open it in the ruleset editor
  6. Search CA1034 in the search box in the ruleset editor:

Expected Searching CA1034 shows same 2 entries as were seen in step 6 for Repro 1.

Actual Only one matching entry, which is for Managed Binary Analysis (old FxCop), with value None. image

User feels CA1034 analyzer in FxCopAnalyzers package is suppressed, but actually it is still running and you will see CA1034 diagnostics reported by the analyzer in the error list. Checking/Un-checking the CA1034 checkbox for Managed Binary Analysis has no effect on the FxCop analyzer. The only workaround for the user is to manually edit the ruleset file to add the following entry to suppress this rule from the analyzer package:

<Rules AnalyzerId="Microsoft.CodeQuality.Analyzers" RuleNamespace="Microsoft.CodeQuality.Analyzers">
    <Rule Id="CA1034" Action="None" />
</Rules>
Pilchie commented 6 years ago

@mavasani - any idea what's going wrong in the new project system to trigger this?

mavasani commented 6 years ago

I recall @tmeschter fixed a bunch of stuff to get this to even work for the new project system. The API tying up the ruleset editor to Roslyn to get the correct entries is this one: http://source.roslyn.io/#Microsoft.VisualStudio.LanguageServices/Implementation/Diagnostics/IVisualStudioDiagnosticAnalyzerService.cs,20. Probably run it through the debugger to see why we are not receiving the supported analyzer rule IDs.

curia-damiano commented 6 years ago

+1

jnm2 commented 5 years ago

If you don't have a legacy csproj in your solution, is there a way to get any PackageReference analyzers to show up, or projects to show up in the 'Project:' dropdown?

mzhukovs commented 5 years ago

I'm still seeing this issue in VS2019.... my .ruleset file sets Action to None for rules I don't care for and they still get flagged in Error list regardless. E.g.

<?xml version="1.0" encoding="utf-8"?>

Is there an ETA for a fix?