-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.psm1
60 lines (52 loc) · 1.75 KB
/
Utils.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
$ErrorActionPreference = [Management.Automation.ActionPreference]::Stop
Set-StrictMode -Version Latest
function Get-RemoteFile {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $Uri,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $OutFile,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $Sha512
)
Invoke-WebRequest -UserAgent wget -Uri $Uri -OutFile $OutFile
Unblock-File $OutFile
if ((Get-FileHash -Algorithm SHA512 $OutFile).Hash -ine $Sha512) {
throw [Exception]::new("${OutFile}: incorrect SHA512")
}
}
function Invoke-CheckExitCode {
# [CmdletBinding()] and [Parameter()] are omitted to make sure
# "-i" is not interpreted as "-InformationAction" etc.
$command, $arguments = $args
# Scope $ErrorActionPreference change.
& {
# PowerShell throws on any stderr output if $ErrorActionPreference is set.
$ErrorActionPreference = [Management.Automation.ActionPreference]::Continue
& $command $arguments
}
if ($LASTEXITCODE) {
throw [Exception]::new("$command exited with code $LASTEXITCODE")
}
}
function Invoke-MsBuild {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $CsprojPath,
[string] $ReferencePath
)
$props = (
'/p:Configuration=Release', '/p:Platform=AnyCPU', '/p:TargetFrameworkVersion=4.8',
'/p:DebugType=None', '/p:DebugSymbols=False', '/p:DefineConstants='
)
if ($ReferencePath) {
$props += "/p:ReferencePath=$(Resolve-Path $ReferencePath)"
}
Invoke-CheckExitCode MSBuild.exe $CsprojPath /m /t:Rebuild @props
}