Suchiman / SerilogAnalyzer

Roslyn-based analysis for code using the Serilog logging library. Checks for common mistakes and usage problems.
Apache License 2.0
309 stars 29 forks source link

Analyser is installed as a project dependency and not a build dependency when installed from Nuget #60

Open JinsPeter opened 2 years ago

JinsPeter commented 2 years ago

image When installed SerilogAnalyzer, the package gets installed as a Project dependency rather than a build time dependency?

Below is a sample from a FxCopAnalyzer installation where the visual studio itself marked the package reference as <PrivateAssets> All </PrivateAssets>.

image

Is there anything to be done to install SerilogAnlyzer as a Build dependency. Is it okay if we manually mark it as a PrivateAssets=All?

Suchiman commented 2 years ago

I don't think any of that is necessary, SerilogAnalyzer.dll is neither copied to the output directory nor are you able to access the SerilogAnalyzer namespace in your project where you are referencing the analyzer. Are there any other concerns i'm missing here? Marking it as PrivateAssets=All should be fine though, even though i don't see what that would change.

Banner-Keith commented 2 years ago

My understanding is that if someone were to include this in their project and generate a nuget package from that this package would be listed as a dependency and it probably shouldn't be. That's why PrivateAssets should probably be included by default.

sungam3r commented 2 years ago

Are there any other concerns i'm missing here?

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <TargetFramework>netstandard2.0</TargetFramework>
    <IsPackable>true</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="SerilogAnalyzer" Version="0.15.0" />
  </ItemGroup>

</Project>

From NugetPackageExplorer on dummy project built with SerilogAnalyzer: изображение

cremor commented 1 year ago

@Suchiman Your package should be flagged as a developmentDependency. If it has that flag then Visual Studio should automatically create correct attributes in the <PackageReference> tag for your users to not include it as a dependency.