Is there a way to create a NuGet package where when the package is installed into a project it adds references to the dlls with "Copy Local" set to false?
I assume it would be some kind of script within the 'install.ps1' file.
Yes you can do this with install.ps1, as you guessed.
Here's an example install.ps1 that will flip the flag on System.dll every time you run it. You should be able to get an idea how to do what you want using this example:
param($installPath, $toolsPath, $package, $project)
foreach ($reference in $project.Object.References)
{
if($reference.Name -eq "System")
{
if($reference.CopyLocal -eq $true)
{
$reference.CopyLocal = $false;
}
else
{
$reference.CopyLocal = $true;
}
}
}
But this MSDN documentation should help.
Object
Hanselman uses resolves to the VSProject Interface.
$project
variable NuGet gives you resolves to the Project Interface.
I think this install.ps1 does what you ask for - all DLLs added by the package are given a Copy Local value of false. Note that here I'm not doing anything with the AssemblyReferences list other than getting all of the names from it - you may have to do something more if you want conditions based on target framework, etc.
param($installPath, $toolsPath, $package, $project)
$asms = $package.AssemblyReferences | %{$_.Name}
foreach ($reference in $project.Object.References)
{
if ($asms -contains $reference.Name + ".dll")
{
$reference.CopyLocal = $false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With