/
RestoreNuGet.psm1
39 lines (33 loc) · 1.12 KB
/
RestoreNuGet.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Set-StrictMode -Version latest
$ErrorActionPreference = "Stop"
[String]$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
Import-Module "$ScriptDir\Helper.psm1"
Import-Module "$ScriptDir\Configuration.psm1"
# -------------------------------------------------------------------------------------------------------------------------------------
# Tools
[string] $NugetToolPath = "$ScriptDir\bin\nuget.exe"
# -------------------------------------------------------------------------------------------------------------------------------------
function RestoreNuGet
{
Param
(
[Parameter()][string] $SolutionPath = $global:SolutionPath,
[Parameter()][switch] $PauseOnError
)
Try
{
Write-Host -Foreground "Green" "Restoring NuGet packages..."
EnvRunExec ( "$NugetToolPath", "restore", "$SolutionPath" )
New-Item "$global:NugetCachePath" -ItemType Directory -ErrorAction Ignore
echo $null >> "$global:NugetCachePath\.nuget_package_cache"
}
Catch [Exception]
{
# tell the caller it has all gone wrong
echo $_.Exception|format-list -force
if ($PauseOnError) {
Read-Host "Press ANY key..."
}
exit(-1)
}
}