Search code examples
.netpowershellnugetnuspec

Nuget $project.Object.References.Add fails in install PS-script


I have my nuget package, lets call it A that has a dependency on another public package Nunit.Runners

When A depends on Nunit.Runners it doesn't add the assemblies I need into my project, the assemblies I depend on are in NUnit.Runners.2.6.3\tools\lib so, because nuget only adds referces to assemblies in lib, I think I need to add a Install.ps1 to my nuget package

I now have

param($installPath, $toolsPath, $package, $project)

$NunitRunners = join-path -path $packagesFolder -childpath "NUnit.Runners.2.6.3"

$project.Object.References.Add($NunitRunners+"\nunit.core")
$project.Object.References.Add($NunitRunners+"\nunit.core.interfaces")

But it's throwing

 Exception calling "Add" with "1" argument(s): "Unspecified error
 (Exception from HRESULT: 0x80004005 (E_FAIL))" At

 + $project.Object.References.Add <<<< ($NunitRunners+"nunit.core.dll")
     + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
     + FullyQualifiedErrorId : ComMethodTargetInvocation

Any pointers as to why this is throwing on "Add" super welcome

My install.ps1 (here for reference)

param($installPath, $toolsPath, $package, $project)

write-host "Install path" $installPath
$packagesFolder = Split-Path -Path $installPath -Parent
write-host "packages folder" $packagesFolder
write-host $toolsPath
write-host $package

$NunitRunners = join-path -path $packagesFolder -childpath "NUnit.Runners.2.6.3"
write-host $NunitRunners
$project.Object.References.Add($NunitRunners+"\nunit.core")
$project.Object.References.Add($NunitRunners+"\nunit.core.interfaces")

BTW I just need to reference those two assemblies, I don't need to reference nunit.framework

NOTE: I did see this thread in codeplex but nothing there pointed to a solution (ie the project is not client profile and the assemblies shouldn't be on the GAC)


Solution

  • The paths to NUnit.Core.dll and NUnit.Core.Interfaces.dll are incorrect.

    Currently $NunitRunners is pointing to packages\NUnit.Runners.2.6.3 when it should be pointing to packages\NUnit.Runners.2.6.3\tools\lib.

    So you can either change the $NunitRunners path or add it later on when you add the references:

     $project.Object.References.Add($NunitRunners+"\tools\lib\nunit.core.dll")
     $project.Object.References.Add($NunitRunners+"\tools\lib\nunit.core.interfaces.dll")