Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile-time only Nuget dependency (FxCop)

I am creating a .Net Standard 2.0 Nuget package and I want to perform static code analysis for the build. However, when I add the Microsoft.CodeAnalysis.FxCopAnalyzers package it becomes a runtime dependency, so any projects that reference my Nuget package are also installing analyzers. I feel those should be opt-in concerns by the calling code.

Is there anyway to prevent that dependency from being enforced?

like image 951
scottrudy Avatar asked Aug 13 '18 19:08

scottrudy


1 Answers

I ended up finding the solution on my own. It just took a little more research on the Package Reference syntax in project files, specifically Controlling Dependency Assets. The key was to open up the *.csproj file and add a PrivateAssets node like the following (note ExcludeAssets and IncludeAssets are set to the default values and could have been omitted):

<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.1">
  <PrivateAssets>all</PrivateAssets>
  <ExcludeAssets>none</ExcludeAssets>
  <IncludeAssets>all</IncludeAssets>
</PackageReference>
like image 100
scottrudy Avatar answered Sep 28 '22 03:09

scottrudy