Skip to content

Instantly share code, notes, and snippets.

@dadhi
Created November 23, 2020 20:47
Show Gist options
  • Save dadhi/6f950af0169b71f4c2a5614793bf9420 to your computer and use it in GitHub Desktop.
Save dadhi/6f950af0169b71f4c2a5614793bf9420 to your computer and use it in GitHub Desktop.
Control PackageReference

NuGet/Home#5986 (comment)

I've found that you can manually control which .dlls to reference and which .dlls to copy to output from a NuGet package if you turn off all assets on the PackageReference:

<PackageReference Include="Foo.MyPackage" Version="1.0.0" ExcludeAssets="all" GeneratePathProperty="true" />

and then manually reference the .dlls you need:

<Reference Include="$(PkgFoo_MyPackage)\lib\net45\CopyThis.dll">
  <Private>true</Private>
</Reference>
<Reference Include="$(PkgFoo_MyPackage)\lib\net45\DontCopyThis.dll">
  <Private>false</Private>
</Reference>
<None Include="$(PkgFoo_MyPackage)\lib\net45\CopyThisButDontReference.dll">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

Note the usage of GeneratePathProperty on the PackageReference to generate the Pkg*** property, where the package name is prefixed with Pkg and dots replaced with underscores.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment