visual-studionugetpackagereference

Exclude dependencies when installing a nuget package in Visual Studio using PackageReference


Is it possible to exclude a package's dependencies when it is included in a VS project via PackageReference? I would like to only include the contents of the compile/runtime assets.

In my project I need to add a package for it's functionality but one if its dependencies conflicts with a later version I need to use, supplied by my own project. I don't have access to the package so can't update its dependencies but I know it can work fine with the later version that my project uses. I thought I can use a binding redirect but each time I build my project its random which version of the dependency will show up the output dir so sometimes the new dependency isn't even available to redirect to.

I tried adding IncludeAssets like below but I still see the dependencies downloaded in the .nuget packages foldder.

<PackageReference Include="Package_I_Want_But_Without_Its_Dependencies" Version="1.0.0">
    <IncludeAssets>runtime</IncludeAssets>
</PackageReference>

Is there another setting I am missing or is what I am looking for not possible? Perhaps another solution altogether?


Solution

  • Is there another setting I am missing or is what I am looking for not possible? Perhaps another solution altogether?

    The setting you are looking for is impossible, IncludeAssets can only affect the dependencies of current project, it will not affect global nuget cache path. That path will contains everything of a package.

    Even you use something like this:

    <ExcludeAssets>all</ExcludeAssets>

    It will also be unable to affect global cache path.