roslyn-sdk
roslyn-sdk copied to clipboard
Pack library with analyzer
If we have:
Lib.csproj
Lib.Analyzers.csproj
And we want to pack so that Lib.nupkg has a package dependency on Lib.Analyzers.nupkg
An example of the desired result is: Microsoft.CodeAnalysis.Common that has a dependency on Microsoft.CodeAnalysis.Analyzers
For anyone familiar with paket it is done like this using paket:
dependencies
Lib.Analyzers
In paket.template
Is there support for this scenario and if so where is it documented?
https://github.com/NuGet/Home/issues/9106
@AArnott how has this experience been for vs-threading?
It's been good.... ish. A few caveats:
- Packages that consume your package can't suppress your analyzers for the final customer that might not even be using your API directly. See https://github.com/microsoft/vs-streamjsonrpc/issues/195, https://github.com/NuGet/Home/issues/6279.
- A project reference from your self-packing library project to your self-packing analyzer project is the easiest way to end up with a library package that references the analyzer package. But this only works if the analyzer's TFMs are compatible with all your libary's TFMs. All sorts of hacks to avoid an assembly reference and therefore calm NuGet's nerves about a reference to a project with supposedly incompatible TFMs have been tried with little success. This also means that every time you build your library, the analyzers have to build first even though that's irrelevant to your library. There's no way to define a package reference without a project reference without a custom .nuspec template file, which is a pain to maintain and would require some sort of variable substitution during the build to make sure the version of the analyzer dependency matches the version of the analyzer package that would actually be built.
This is definitely an area where I'd like to see NuGet improve the story around.