Functions/Install-ToolsPackageFromNuget.ps1

function Install-ToolsPackageFromNuget {
    [CmdletBinding()]
    param($PackagePath, $package, $subPath, $version, $environmentVariablesToSet
        ,$nugetextraparams    )

    Write-Host "Installing Package $package"
    Write-Verbose "Using nuget in $($env:nugetPath)"
    $testPath = Join-Path(Join-Path $PackagePath $package) $subPath
    
    if (-not (Test-path $testPath)) {
        $nugetparams = @("install", $package, "-ExcludeVersion", "-OutputDirectory", $PackagePath)
        if ($version) { $nugetparams += "-version", $version }
        &($env:nugetPath) $nugetparams @nugetextraparams
    }
    if ($environmentVariablesToSet) {
        $environmentVariablesToSet | foreach-object {
            Write-verbose "Setting $_ to $testPath"
           if ($_ -eq "path" -and $env:PATH.split([io.path]::PathSeparator) -notcontains $testPath) {
                $env:PATH= $env:PATH + [io.path]::PathSeparator + "$testPath"
           }
               else{
                set-item -path "env:$_" -value $testPath
            } 
        }
    }
}