57 lines
1.8 KiB
PowerShell
57 lines
1.8 KiB
PowerShell
|
function Get-PackageFromProget {
|
|||
|
<#
|
|||
|
.SYNOPSIS
|
|||
|
Downloads a .nupkg from a Proget source given a package name/version.
|
|||
|
.PARAMETER source
|
|||
|
The nuget source URL of the package repository.
|
|||
|
.PARAMETER name
|
|||
|
The name/ID of the package.
|
|||
|
.PARAMETER version
|
|||
|
The version of the package.
|
|||
|
.PARAMETER output
|
|||
|
The download folder for the package.
|
|||
|
#>
|
|||
|
[CmdletBinding()]
|
|||
|
Param(
|
|||
|
[Parameter(Mandatory = $false)]
|
|||
|
[Alias("s")]
|
|||
|
[string]$source = "",
|
|||
|
[Parameter(Mandatory = $false)]
|
|||
|
[Alias("n")]
|
|||
|
[string]$name = "",
|
|||
|
[Parameter(Mandatory = $false)]
|
|||
|
[Alias("v")]
|
|||
|
[string]$version = "",
|
|||
|
[Parameter(Mandatory = $false)]
|
|||
|
[Alias("o")]
|
|||
|
[string]$output = "",
|
|||
|
[Parameter(Mandatory = $false)]
|
|||
|
[pscredential]$nugetCredential = $null
|
|||
|
)
|
|||
|
|
|||
|
$loglead = Get-LogLeadName;
|
|||
|
|
|||
|
Write-Host "$loglead : Downloading $name|$version from package source `"$source`"";
|
|||
|
|
|||
|
# If the source has a / on the end remove it.
|
|||
|
$lastChar = $source.Substring($source.Length-1, 1);
|
|||
|
if(($lastChar -eq "/") -or ($lastChar -eq "\")) {
|
|||
|
$source = $source.Substring(0, $source.Length - 1);
|
|||
|
}
|
|||
|
|
|||
|
$url = "$source/package/$name/$version";
|
|||
|
Write-Verbose "$loglead : Downloading package .nupkg from URL `"$url`" to `"$output`"";
|
|||
|
try {
|
|||
|
if(Test-Path $output) {
|
|||
|
Write-Warning "$loglead : File `"$output`" already exists. Overwriting.";
|
|||
|
}
|
|||
|
$header = (Get-BasicAuthHeader -Credential $nugetCredential);
|
|||
|
Invoke-WebRequest -Headers $header -Uri $url -OutFile $output -UseBasicParsing;
|
|||
|
} catch {
|
|||
|
Write-Error "$loglead : Failed to download package. `n$($_.Exception.Message)";
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
Write-Host "$loglead : Download complete.";
|
|||
|
}
|