dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.12k stars 4.04k forks source link

Question: Packaging of Roslyn analyzer nuget #65635

Open nschuessler opened 2 years ago

nschuessler commented 2 years ago

I have gotten some feedback on my analyzer NuGet package from a customer.

The 'Bug' is that my analyzer NuGet package has dependencies on other NuGet packages and that causes problems. When adding my analyzers package to a project I get an entry like this:

 <ItemGroup>
    <PackageReference Include="My.Analyzers" Version="403.22.1118.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

There are only analyzers in the package, but I suspect because build and/or runtime are added by default, that this ties my analyzer runtime to the target of the project and causes customer issues (i.e. if I built my analyzer for .Net 6.0, it wouldn't work in targeting a net framework project)?

My NuGet is built using an exclusion list found in an article online:

        <file src="bin\Release\*.dll" target="analyzers\dotnet" exclude="**\Microsoft.CodeAnalysis.CSharp.*;**\Microsoft.CodeAnalysis.VisualBasic.*;**\Microsoft.CodeAnalysis.dll;**\Microsoft.CodeAnalysis.Workspaces.dll;**\System.Collections.Immutable.*;**\System.Reflection.Metadata.*;**\System.Composition.*" />

But because my ADO pipeline runs a script to patch the .nuspec with dependencies derived from the PackageReference entries in the .csproj, the NuGet has dependencies, causing them all to be installed.

Questions: 1) Is the right thing to do to remove the NuGet package dependencies and include the flat files only (vs remove the flat files and go with the

2) My understanding is your install script must install all binaries into Visual Studio IDE to be able to find the dependencies for complex analyzers, even if the binaries don't contain the actual analyzer .. correct? This yields to ugly UI vs the organized (nested) NuGet package dependencies UI:

image

3) There seems to be bad problems whether you include binaries in your analyzers NuGet or not. Will there be an effort to make this cleaner for developers?

i.e.

Thanks

arunchndr commented 1 year ago

@mavasani to assess if we can make a recommendation here.