Closed joelverhagen closed 1 week ago
I saw this approach in your code but this seems like a pretty extreme measure
That doesn't address the same problem you're seeing and isn't extreme. It's necessary to prevent any dependencies in the analyzers from being exposed as nuget dependencies. Analyzers must be entirely self-contained, so any dependencies they have that aren't provided by the compiler must be bundled in the nuget package itself, and thus there is no need or desire to have the package itself express dependencies to support analyzers. The xml snippet you found prevents these dependencies from showing up in the package.
It's entirely separate the problem you're facing, which is totally a legit complaint. Sadly, nuget doesn't support PrivateAssets="analyzers"
or I would very happily do that, which would prevent analyzers associated with upstream runtime dependency packages from activating for your project.
This has been a long outstanding feature request against nuget itself, as you can see at https://github.com/microsoft/vs-streamjsonrpc/issues/195, which is the same as this one except it was filed against the StreamJsonRpc library.
The request on nuget is here: https://github.com/NuGet/Home/issues/6279 (please 👍🏻 vote it up!)
In the meantime, there are only two options:
I would expect MessagePack-related analyzers to run but not Visual Studio ones
FYI these "Visual Studio ones" are not specific to Visual Studio, and in fact many of them may be useful for most apps to have. In fact some of them are so generally interesting that the .NET SDK started porting them from the vs-threading analyzer library to the SDK a while back. That work was never finished, unfortunately.
A bunch of
VSTHRD
warnings and errors appear in my project when I reference Nerdbank.MessagePack 0.2.34-alpha. I believe this is due to VS threading analyzers you use in the project.I was able to suppress them by doing
<ExcludeAssets>analyzers</ExcludeAssets>
on the Nerdbank.MessagePack<ProjectReference>
but this forced me to lift the dependency to all of my projects that transitively reference Nerdbank.MessagePack.I saw this approach in your code but this seems like a pretty extreme measure since I just want to suppress the VS Threading analyzer coming from Nerdbank.MessagePack. https://github.com/AArnott/Nerdbank.MessagePack/blob/ad761abcda5c8951be7863fecd05567b24cf2d9f/src/Analyzers.props#L11-L17
Is this expected? Personally, I would expect MessagePack-related analyzers to run but not Visual Studio ones.
Right now, I preferred working around the problem by simply suppressing the message codes I didn't want, e.g.