functions/Install-ToolsPackageFromNuget.ps1

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

    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
    }
    if ($environmentVariablesToSet) {
        $environmentVariablesToSet | foreach-object {
            Write-verbose "Setting $_ to $testPath"
           if ($_ -eq "path" -and $env:path.split(";") -notcontains $testPath) {
                $env:path = $env:path + ";$testPath"
           }
               else{
                set-item -path "env:$_" -value $testPath
            } 
        }
    }
}