Skip to content

Commit 8be2d8c

Browse files
committed
Specifically, this merges [4d2be89 from that repo](AArnott/Library.Template@4d2be89).
2 parents 4f137b9 + 4d2be89 commit 8be2d8c

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tools/Install-NuGetPackage.ps1

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<#
2+
.SYNOPSIS
3+
Installs a NuGet package.
4+
.PARAMETER PackageID
5+
The Package ID to install.
6+
.PARAMETER Version
7+
The version of the package to install. If unspecified, the latest stable release is installed.
8+
.PARAMETER Source
9+
The package source feed to find the package to install from.
10+
.PARAMETER PackagesDir
11+
The directory to install the package to. By default, it uses the Packages folder at the root of the repo.
12+
.PARAMETER ConfigFile
13+
The nuget.config file to use. By default, it uses :/nuget.config.
14+
.OUTPUTS
15+
System.String. The path to the installed package.
16+
#>
17+
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='Low')]
18+
Param(
19+
[Parameter(Position=1,Mandatory=$true)]
20+
[string]$PackageId,
21+
[Parameter()]
22+
[string]$Version,
23+
[Parameter()]
24+
[string]$Source,
25+
[Parameter()]
26+
[switch]$Prerelease,
27+
[Parameter()]
28+
[string]$PackagesDir="$PSScriptRoot\..\packages",
29+
[Parameter()]
30+
[string]$ConfigFile="$PSScriptRoot\..\nuget.config",
31+
[Parameter()]
32+
[ValidateSet('Quiet','Normal','Detailed')]
33+
[string]$Verbosity='normal'
34+
)
35+
36+
$nugetPath = & "$PSScriptRoot\Get-NuGetTool.ps1"
37+
38+
try {
39+
Write-Verbose "Installing $PackageId..."
40+
$nugetArgs = "Install",$PackageId,"-OutputDirectory",$PackagesDir,'-ConfigFile',$ConfigFile
41+
if ($Version) { $nugetArgs += "-Version",$Version }
42+
if ($Source) { $nugetArgs += "-FallbackSource",$Source }
43+
if ($Prerelease) { $nugetArgs += "-Prerelease" }
44+
$nugetArgs += '-Verbosity',$Verbosity
45+
46+
if ($PSCmdlet.ShouldProcess($PackageId, 'nuget install')) {
47+
$p = Start-Process $nugetPath $nugetArgs -NoNewWindow -Wait -PassThru
48+
if ($null -ne $p.ExitCode -and $p.ExitCode -ne 0) { throw }
49+
}
50+
51+
# Provide the path to the installed package directory to our caller.
52+
Write-Output (Get-ChildItem "$PackagesDir\$PackageId.*")[0].FullName
53+
} finally {
54+
Pop-Location
55+
}

0 commit comments

Comments
 (0)