-
Notifications
You must be signed in to change notification settings - Fork 28
/
init.ps1
executable file
·156 lines (141 loc) · 7.08 KB
/
init.ps1
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Installs dependencies required to build and test the projects in this repository.
.DESCRIPTION
This MAY not require elevation, as the SDK and runtimes are installed to a per-user location,
unless the `-InstallLocality` switch is specified directing to a per-repo or per-machine location.
See detailed help on that switch for more information.
The CmdEnvScriptPath environment variable may be optionally set to a path to a cmd shell script to be created (or appended to if it already exists) that will set the environment variables in cmd.exe that are set within the PowerShell environment.
This is used by init.cmd in order to reapply any new environment variables to the parent cmd.exe process that were set in the powershell child process.
.PARAMETER InstallLocality
A value indicating whether dependencies should be installed locally to the repo or at a per-user location.
Per-user allows sharing the installed dependencies across repositories and allows use of a shared expanded package cache.
Visual Studio will only notice and use these SDKs/runtimes if VS is launched from the environment that runs this script.
Per-repo allows for high isolation, allowing for a more precise recreation of the environment within an Azure Pipelines build.
When using 'repo', environment variables are set to cause the locally installed dotnet SDK to be used.
Per-repo can lead to file locking issues when dotnet.exe is left running as a build server and can be mitigated by running `dotnet build-server shutdown`.
Per-machine requires elevation and will download and install all SDKs and runtimes to machine-wide locations so all applications can find it.
.PARAMETER NoPrerequisites
Skips the installation of prerequisite software (e.g. SDKs, tools).
.PARAMETER NoNuGetCredProvider
Skips the installation of the NuGet credential provider. Useful in pipelines with the `NuGetAuthenticate` task, as a workaround for https://github.com/microsoft/artifacts-credprovider/issues/244.
This switch is ignored and installation is skipped when -NoPrerequisites is specified.
.PARAMETER UpgradePrerequisites
Takes time to install prerequisites even if they are already present in case they need to be upgraded.
No effect if -NoPrerequisites is specified.
.PARAMETER NoRestore
Skips the package restore step.
.PARAMETER NoToolRestore
Skips the dotnet tool restore step.
.PARAMETER Signing
Install the MicroBuild signing plugin for building test-signed builds on desktop machines.
.PARAMETER Localization
Install the MicroBuild localization plugin for building loc builds on desktop machines.
The environment is configured to build pseudo-loc for JPN only, but may be used to build
all languages with shipping-style loc by using the `/p:loctype=full,loclanguages=vs`
when building.
.PARAMETER Sbom
Install the MicroBuild SBOM plugin.
.PARAMETER AccessToken
An optional access token for authenticating to Azure Artifacts authenticated feeds.
.PARAMETER Interactive
Runs NuGet restore in interactive mode. This can turn authentication failures into authentication challenges.
#>
[CmdletBinding(SupportsShouldProcess = $true)]
Param (
[ValidateSet('repo', 'user', 'machine')]
[string]$InstallLocality = 'user',
[Parameter()]
[switch]$NoPrerequisites,
[Parameter()]
[switch]$NoNuGetCredProvider,
[Parameter()]
[switch]$UpgradePrerequisites,
[Parameter()]
[switch]$NoRestore,
[Parameter()]
[switch]$NoToolRestore,
[Parameter()]
[switch]$Signing,
[Parameter()]
[switch]$Localization,
[Parameter()]
[switch]$SBOM,
[Parameter()]
[string]$AccessToken,
[Parameter()]
[switch]$Interactive
)
$EnvVars = @{}
$PrependPath = @()
if (!$NoPrerequisites) {
if (!$NoNuGetCredProvider) {
& "$PSScriptRoot\tools\Install-NuGetCredProvider.ps1" -AccessToken $AccessToken -Force:$UpgradePrerequisites
}
& "$PSScriptRoot\tools\Install-DotNetSdk.ps1" -InstallLocality $InstallLocality
if ($LASTEXITCODE -eq 3010) {
Exit 3010
}
# The procdump tool and env var is required for dotnet test to collect hang/crash dumps of tests.
# But it only works on Windows.
if ($env:OS -eq 'Windows_NT') {
$EnvVars['PROCDUMP_PATH'] = & "$PSScriptRoot\azure-pipelines\Get-ProcDump.ps1"
}
}
# Workaround nuget credential provider bug that causes very unreliable package restores on Azure Pipelines
$env:NUGET_PLUGIN_HANDSHAKE_TIMEOUT_IN_SECONDS = 20
$env:NUGET_PLUGIN_REQUEST_TIMEOUT_IN_SECONDS = 20
Push-Location $PSScriptRoot
try {
$HeaderColor = 'Green'
$RestoreArguments = @()
if ($Interactive) {
$RestoreArguments += '--interactive'
}
if (!$NoRestore -and $PSCmdlet.ShouldProcess("NuGet packages", "Restore")) {
Write-Host "Restoring NuGet packages" -ForegroundColor $HeaderColor
dotnet restore @RestoreArguments
if ($lastexitcode -ne 0) {
throw "Failure while restoring packages."
}
}
if (!$NoToolRestore -and $PSCmdlet.ShouldProcess("dotnet tool", "restore")) {
dotnet tool restore @RestoreArguments
if ($lastexitcode -ne 0) {
throw "Failure while restoring dotnet CLI tools."
}
}
$InstallNuGetPkgScriptPath = "$PSScriptRoot\azure-pipelines\Install-NuGetPackage.ps1"
$nugetVerbosity = 'quiet'
if ($Verbose) { $nugetVerbosity = 'normal' }
$MicroBuildPackageSource = 'https://pkgs.dev.azure.com/devdiv/_packaging/MicroBuildToolset%40Local/nuget/v3/index.json'
if ($Signing) {
Write-Host "Installing MicroBuild signing plugin" -ForegroundColor $HeaderColor
& $InstallNuGetPkgScriptPath MicroBuild.Plugins.Signing -source $MicroBuildPackageSource -Verbosity $nugetVerbosity
$EnvVars['SignType'] = "Test"
}
if ($Localization) {
Write-Host "Installing MicroBuild localization plugin" -ForegroundColor $HeaderColor
& $InstallNuGetPkgScriptPath MicroBuild.Plugins.Localization -source $MicroBuildPackageSource -Verbosity $nugetVerbosity
$EnvVars['LocType'] = "Pseudo"
$EnvVars['LocLanguages'] = "JPN"
}
if ($SBOM) {
Write-Host "Installing MicroBuild SBOM plugin" -ForegroundColor $HeaderColor
& $InstallNuGetPkgScriptPath MicroBuild.Plugins.Sbom -source $MicroBuildPackageSource -Verbosity $nugetVerbosity
# The feed with the latest versions of the tool is at 'https://1essharedassets.pkgs.visualstudio.com/1esPkgs/_packaging/SBOMTool/nuget/v3/index.json',
# but we'll use the feed that the SBOM task itself uses to install the tool for consistency.
$PkgMicrosoft_ManifestTool_CrossPlatform = & $InstallNuGetPkgScriptPath Microsoft.ManifestTool.CrossPlatform -source $MicroBuildPackageSource -Verbosity $nugetVerbosity
$EnvVars['GenerateSBOM'] = "true"
$EnvVars['PkgMicrosoft_ManifestTool_CrossPlatform'] = $PkgMicrosoft_ManifestTool_CrossPlatform
}
& "$PSScriptRoot/tools/Set-EnvVars.ps1" -Variables $EnvVars -PrependPath $PrependPath | Out-Null
}
catch {
Write-Error $error[0]
exit $lastexitcode
}
finally {
Pop-Location
}