2

I have a .NET project that references a library from another project via an internal NuGet server. The referenced project uses third party code analyzers (StyleCop) also referenced via NuGet and does not mark the assets as private. Consequently, these analyzers are pulled in and ran as part of my project.

I understand that analyzer rules can be suppressed using a combination of .editorconfig and/or NoWarn. However, I would like to prevent the analyzers from running at all for my project. I've tried setting ExcludeAssets=analyzers in my package reference, but this doesn't appear to have an effect.

<PackageReference Include="LibraryWithAnalyzers" Version="*" ExcludeAssets="analyzers" />

Is there something I am missing?

1
  • FWIW, I believe that any analyzer rules with a severity of "none" aren't run. So if you can't find a good way to remove the dll entirely, at least they shouldn't have much of an impact if you turn them off with .editorconfig. Commented Jan 31 at 19:38

1 Answer 1

0

Not exactly an ideal solution, but adding the following target seems to work:

<Target Name="DisableStyleCop" BeforeTargets="CoreCompile">
  <ItemGroup>
    <Analyzer Remove="@(Analyzer)" Condition="'%(Filename)' == 'StyleCop.Analyzers' OR '%(Filename)' == 'StyleCop.Analyzers.CodeFixes'" />
  </ItemGroup>
</Target>

Thanks to this answer for setting me on the right track.

This workaround would not be not needed if the referenced project had set PrivateAssets="all" when referencing StyleCop. Whether or not this was an oversight or due to heavy-handed stylistic opinions is not clear.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.