Reputation: 1173
I used to have nuspec for my library. There I had roslyn analyzers package added using <dependency/>
. The package is not required for the lib itself. It is needed for the library clients only. Now I use new sdk-style project. The only way to add nuget dependencies there, that I see, is to use <PackageReference/>
. But that will install the package to the lib itself too. And in my case it breaks the project because analyzers are designed for the clients only. Is there any way to force some package for the clients but avoid for the package. The only option that I see tight now is to use NuspecFile but I want to get rid of nuspec.
Upvotes: 0
Views: 531
Reputation: 22099
I do not think, that this is possible with packages references, because it contradicts the concept of dependencies. If your project does not depend on a package, then it is by design not a dependency, especially not if it is only used by clients or it must not be included into your project. It is the responsibility of the client to use the package or not.
I want to force the installation because it contains compile-time checks to avoid incorrect usage.
There is no need for your library to include the package, because there is no dependency. It is an option to help avoid incorrect usage. I think that it would be more resonable to let clients choose themselves, whether or not they want to use Roslyn analyzers or not. Keep in mind that there are other analyzers, too, and not everybody might be able to use yours or even want to use yours, but you can recommend it on your project site.
The reason why you can add unused dependencies to NuSpec files is that there is no way for the package manager to know if the package is used anywhere, since there is no build environment or compiler that can check it. It is more of a loophole by design and you may not rely on that.
Upvotes: 1