Skip to content

Commit 640eac8

Browse files
Merge pull request #1716 from PowerShell/andschwa/dotnet
Use global `dotnet` and update build dependencies
2 parents 458899d + c965f6c commit 640eac8

File tree

4 files changed

+68
-136
lines changed

4 files changed

+68
-136
lines changed

.vsts-ci/azure-pipelines-release.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ stages:
2929
jobs:
3030
- job: Build
3131
pool:
32-
vmImage: windows-2019
32+
name: 1ES
33+
demands: ImageOverride -equals PSMMS2019-Secure
3334
steps:
3435
- template: templates/ci-general.yml
3536

@@ -39,7 +40,7 @@ stages:
3940
- job: Sign
4041
pool:
4142
name: 1ES
42-
demands: ImageOverride -equals MMSWindows2019-Secure
43+
demands: ImageOverride -equals PSMMS2019-Secure
4344
variables:
4445
- group: ESRP
4546
steps:
@@ -51,7 +52,8 @@ stages:
5152
- deployment: Publish
5253
environment: PowerShellEditorServices
5354
pool:
54-
vmImage: ubuntu-latest
55+
name: 1ES
56+
demands: ImageOverride -equals PSMMSUbuntu20.04-Secure
5557
variables:
5658
- group: Publish
5759
strategy:

.vsts-ci/templates/ci-general.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ steps:
1111
script: $PSVersionTable
1212
pwsh: ${{ parameters.pwsh }}
1313

14+
- task: UseDotNet@2
15+
displayName: Install .NET 6.0.x SDK
16+
inputs:
17+
packageType: sdk
18+
version: 6.0.x
19+
performMultiLevelLookup: true
20+
21+
- task: UseDotNet@2
22+
displayName: Install .NET 3.1.x runtime
23+
inputs:
24+
packageType: runtime
25+
version: 3.1.x
26+
performMultiLevelLookup: true
27+
1428
- task: PowerShell@2
1529
displayName: Build and test
1630
inputs:

PowerShellEditorServices.build.ps1

Lines changed: 47 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ param(
1919
[string[]]$TestArgs = @("--logger", "trx")
2020
)
2121

22-
#Requires -Modules @{ModuleName="InvokeBuild";ModuleVersion="3.2.1"}
22+
#Requires -Modules @{ModuleName="InvokeBuild"; ModuleVersion="5.0.0"}
23+
#Requires -Modules @{ModuleName="platyPS"; ModuleVersion="0.14.0"}
2324

2425
$script:dotnetTestArgs = @(
2526
"test"
@@ -52,84 +53,18 @@ if (Get-Command git -ErrorAction SilentlyContinue) {
5253
git update-index --assume-unchanged "$PSScriptRoot/src/PowerShellEditorServices.Hosting/BuildInfo.cs"
5354
}
5455

55-
function Install-Dotnet {
56-
param (
57-
[string[]]$Channel,
58-
[switch]$Runtime
59-
)
56+
task FindDotNet {
57+
assert (Get-Command dotnet -ErrorAction SilentlyContinue) "dotnet not found, please install it: https://aka.ms/dotnet-cli"
58+
assert ([Version](dotnet --version) -ge [Version]("6.0")) ".NET SDK 6.0 or higher is required, please update it: https://aka.ms/dotnet-cli"
6059

61-
$env:DOTNET_INSTALL_DIR = "$PSScriptRoot/.dotnet"
62-
63-
$components = if ($Runtime) { "Runtime " } else { "SDK and Runtime " }
64-
$components += $Channel -join ', '
65-
66-
Write-Host "Installing .NET $components" -ForegroundColor Green
67-
68-
# The install script is platform-specific
69-
$installScriptExt = if ($script:IsNix) { "sh" } else { "ps1" }
70-
$installScript = "dotnet-install.$installScriptExt"
71-
72-
# Download the official installation script and run it
73-
$installScriptPath = Join-Path ([System.IO.Path]::GetTempPath()) $installScript
74-
Invoke-WebRequest "https://dot.net/v1/$installScript" -OutFile $installScriptPath
75-
76-
# Download and install the different .NET channels
77-
foreach ($dotnetChannel in $Channel)
78-
{
79-
if ($script:IsNix) {
80-
chmod +x $installScriptPath
81-
}
82-
83-
$params = if ($script:IsNix) {
84-
@('-Channel', $dotnetChannel, '-InstallDir', $env:DOTNET_INSTALL_DIR, '-NoPath', '-Verbose')
85-
} else {
86-
@{
87-
Channel = $dotnetChannel
88-
InstallDir = $env:DOTNET_INSTALL_DIR
89-
NoPath = $true
90-
Verbose = $true
91-
}
92-
}
93-
94-
# Install just the runtime, not the SDK
95-
if ($Runtime) {
96-
if ($script:IsNix) { $params += @('-Runtime', 'dotnet') }
97-
else { $params['Runtime'] = 'dotnet' }
98-
}
99-
100-
exec { & $installScriptPath @params }
60+
# Anywhere other than on a Mac with an M1 processor, we additionally
61+
# need the .NET 3.1 runtime for our netcoreapp3.1 framework.
62+
if (!$script:IsAppleM1) {
63+
$runtimes = dotnet --list-runtimes
64+
assert ($runtimes -match "Microsoft.NETCore.App 3.1") ".NET Runtime 3.1 required but not found!"
10165
}
10266

103-
$env:PATH = $env:DOTNET_INSTALL_DIR + [System.IO.Path]::PathSeparator + $env:PATH
104-
105-
Write-Host '.NET installation complete' -ForegroundColor Green
106-
}
107-
108-
task SetupDotNet -Before Clean, Build, TestServerWinPS, TestServerPS7, TestServerPS72, TestE2E {
109-
110-
$dotnetPath = "$PSScriptRoot/.dotnet"
111-
$dotnetExePath = if ($script:IsNix) { "$dotnetPath/dotnet" } else { "$dotnetPath/dotnet.exe" }
112-
113-
if (!(Test-Path $dotnetExePath)) {
114-
# TODO: Test .NET 5 with PowerShell 7.1
115-
#
116-
# We use the .NET 6 SDK, so we always install it and its runtime.
117-
Install-Dotnet -Channel '6.0' # SDK and runtime
118-
# Anywhere other than on a Mac with an M1 processor, we additionally
119-
# install the .NET 3.1 and 5.0 runtimes (but not their SDKs).
120-
if (!$script:IsAppleM1) { Install-Dotnet -Channel '3.1','5.0' -Runtime }
121-
}
122-
123-
# This variable is used internally by 'dotnet' to know where it's installed
124-
$script:dotnetExe = Resolve-Path $dotnetExePath
125-
if (!$env:DOTNET_INSTALL_DIR)
126-
{
127-
$dotnetExeDir = [System.IO.Path]::GetDirectoryName($script:dotnetExe)
128-
$env:PATH = $dotnetExeDir + [System.IO.Path]::PathSeparator + $env:PATH
129-
$env:DOTNET_INSTALL_DIR = $dotnetExeDir
130-
}
131-
132-
Write-Host "`n### Using dotnet v$(& $script:dotnetExe --version) at path $script:dotnetExe`n" -ForegroundColor Green
67+
Write-Host "Using dotnet v$(dotnet --version) at path $((Get-Command dotnet).Source)" -ForegroundColor Green
13368
}
13469

13570
task BinClean {
@@ -138,9 +73,8 @@ task BinClean {
13873
Remove-Item $PSScriptRoot\module\PowerShellEditorServices.VSCode\bin -Recurse -Force -ErrorAction Ignore
13974
}
14075

141-
task Clean BinClean,{
142-
exec { & $script:dotnetExe restore }
143-
exec { & $script:dotnetExe clean }
76+
task Clean FindDotNet, BinClean, {
77+
exec { & dotnet clean }
14478
Get-ChildItem -Recurse $PSScriptRoot\src\*.nupkg | Remove-Item -Force -ErrorAction Ignore
14579
Get-ChildItem $PSScriptRoot\PowerShellEditorServices*.zip | Remove-Item -Force -ErrorAction Ignore
14680
Get-ChildItem $PSScriptRoot\module\PowerShellEditorServices\Commands\en-US\*-help.xml | Remove-Item -Force -ErrorAction Ignore
@@ -155,7 +89,7 @@ task Clean BinClean,{
15589
}
15690
}
15791

158-
task CreateBuildInfo -Before Build {
92+
task CreateBuildInfo {
15993
$buildVersion = "<development-build>"
16094
$buildOrigin = "Development"
16195
$buildCommit = git rev-parse HEAD
@@ -174,8 +108,7 @@ task CreateBuildInfo -Before Build {
174108
$propsBody = $propsXml.Project.PropertyGroup
175109
$buildVersion = $propsBody.VersionPrefix
176110

177-
if ($propsBody.VersionSuffix)
178-
{
111+
if ($propsBody.VersionSuffix) {
179112
$buildVersion += '-' + $propsBody.VersionSuffix
180113
}
181114
}
@@ -217,59 +150,55 @@ task SetupHelpForTests {
217150
Write-Host "Updating help for tests"
218151
Update-Help -Module Microsoft.PowerShell.Utility -Force -Scope CurrentUser
219152
}
220-
else
221-
{
222-
Write-Host "Write-Host help found -- Update-Help skipped"
223-
}
224153
}
225154

226-
Task Build {
227-
exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -f $script:NetRuntime.Standard }
228-
exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.PS7 }
229-
if (-not $script:IsNix)
230-
{
231-
exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.Desktop }
155+
Task Build FindDotNet, CreateBuildInfo, {
156+
exec { & dotnet restore }
157+
exec { & dotnet publish -c $Configuration .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -f $script:NetRuntime.Standard }
158+
exec { & dotnet publish -c $Configuration .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.PS7 }
159+
if (-not $script:IsNix) {
160+
exec { & dotnet publish -c $Configuration .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.Desktop }
232161
}
233162

234163
# Build PowerShellEditorServices.VSCode module
235-
exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices.VSCode\PowerShellEditorServices.VSCode.csproj -f $script:NetRuntime.Standard }
164+
exec { & dotnet publish -c $Configuration .\src\PowerShellEditorServices.VSCode\PowerShellEditorServices.VSCode.csproj -f $script:NetRuntime.Standard }
236165
}
237166

238-
task Test SetupHelpForTests,TestServer,TestE2E
167+
task Test TestServer, TestE2E
239168

240-
task TestServer TestServerWinPS,TestServerPS7,TestServerPS72
169+
task TestServer TestServerWinPS, TestServerPS7, TestServerPS72
241170

242-
task TestServerWinPS -If (-not $script:IsNix) {
171+
Task TestServerWinPS -If (-not $script:IsNix) Build, SetupHelpForTests, {
243172
Set-Location .\test\PowerShellEditorServices.Test\
244173
# TODO: See https://github.com/dotnet/sdk/issues/18353 for x64 test host
245174
# that is debuggable! If architecture is added, the assembly path gets an
246175
# additional folder, necesstiating fixes to find the commands definition
247176
# file and test files.
248-
exec { & $script:dotnetExe $script:dotnetTestArgs $script:NetRuntime.Desktop }
177+
exec { & dotnet $script:dotnetTestArgs $script:NetRuntime.Desktop }
249178
}
250179

251-
task TestServerPS7 -If (-not $script:IsAppleM1) {
180+
task TestServerPS7 -If (-not $script:IsAppleM1) Build, SetupHelpForTests, {
252181
Set-Location .\test\PowerShellEditorServices.Test\
253-
exec { & $script:dotnetExe $script:dotnetTestArgs $script:NetRuntime.PS7 }
182+
exec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS7 }
254183
}
255184

256-
task TestServerPS72 {
185+
task TestServerPS72 Build, SetupHelpForTests, {
257186
Set-Location .\test\PowerShellEditorServices.Test\
258-
exec { & $script:dotnetExe $script:dotnetTestArgs $script:NetRuntime.PS72 }
187+
exec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS72 }
259188
}
260189

261-
task TestE2E {
190+
task TestE2E Build, SetupHelpForTests, {
262191
Set-Location .\test\PowerShellEditorServices.Test.E2E\
263192

264193
$env:PWSH_EXE_NAME = if ($IsCoreCLR) { "pwsh" } else { "powershell" }
265194
$NetRuntime = if ($IsAppleM1) { $script:NetRuntime.PS72 } else { $script:NetRuntime.PS7 }
266-
exec { & $script:dotnetExe $script:dotnetTestArgs $NetRuntime }
195+
exec { & dotnet $script:dotnetTestArgs $NetRuntime }
267196

268197
# Run E2E tests in ConstrainedLanguage mode.
269198
if (!$script:IsNix) {
270199
try {
271200
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", "0x80000007", [System.EnvironmentVariableTarget]::Machine);
272-
exec { & $script:dotnetExe $script:dotnetTestArgs $script:NetRuntime.PS7 }
201+
exec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS7 }
273202
} finally {
274203
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", $null, [System.EnvironmentVariableTarget]::Machine);
275204
}
@@ -285,8 +214,7 @@ task LayoutModule -After Build {
285214
$psesCoreHostPath = "$psesBinOutputPath/Core"
286215
$psesDeskHostPath = "$psesBinOutputPath/Desktop"
287216

288-
foreach ($dir in $psesDepsPath,$psesCoreHostPath,$psesDeskHostPath,$psesVSCodeBinOutputPath)
289-
{
217+
foreach ($dir in $psesDepsPath,$psesCoreHostPath,$psesDeskHostPath,$psesVSCodeBinOutputPath) {
290218
New-Item -Force -Path $dir -ItemType Directory
291219
}
292220

@@ -299,56 +227,46 @@ task LayoutModule -After Build {
299227
[void]$includedDlls.Add('System.Management.Automation.dll')
300228

301229
# PSES/bin/Common
302-
foreach ($psesComponent in Get-ChildItem $script:PsesOutput)
303-
{
230+
foreach ($psesComponent in Get-ChildItem $script:PsesOutput) {
304231
if ($psesComponent.Name -eq 'System.Management.Automation.dll' -or
305-
$psesComponent.Name -eq 'System.Runtime.InteropServices.RuntimeInformation.dll')
306-
{
232+
$psesComponent.Name -eq 'System.Runtime.InteropServices.RuntimeInformation.dll') {
307233
continue
308234
}
309235

310-
if ($psesComponent.Extension)
311-
{
236+
if ($psesComponent.Extension) {
312237
[void]$includedDlls.Add($psesComponent.Name)
313238
Copy-Item -Path $psesComponent.FullName -Destination $psesDepsPath -Force
314239
}
315240
}
316241

317242
# PSES/bin/Core
318-
foreach ($hostComponent in Get-ChildItem $script:HostCoreOutput)
319-
{
320-
if (-not $includedDlls.Contains($hostComponent.Name))
321-
{
243+
foreach ($hostComponent in Get-ChildItem $script:HostCoreOutput) {
244+
if (-not $includedDlls.Contains($hostComponent.Name)) {
322245
Copy-Item -Path $hostComponent.FullName -Destination $psesCoreHostPath -Force
323246
}
324247
}
325248

326249
# PSES/bin/Desktop
327-
if (-not $script:IsNix)
328-
{
329-
foreach ($hostComponent in Get-ChildItem $script:HostDeskOutput)
330-
{
331-
if (-not $includedDlls.Contains($hostComponent.Name))
332-
{
250+
if (-not $script:IsNix) {
251+
foreach ($hostComponent in Get-ChildItem $script:HostDeskOutput) {
252+
if (-not $includedDlls.Contains($hostComponent.Name)) {
333253
Copy-Item -Path $hostComponent.FullName -Destination $psesDeskHostPath -Force
334254
}
335255
}
336256
}
337257

338258
# Assemble the PowerShellEditorServices.VSCode module
339259

340-
foreach ($vscodeComponent in Get-ChildItem $script:VSCodeOutput)
341-
{
342-
if (-not $includedDlls.Contains($vscodeComponent.Name))
343-
{
260+
foreach ($vscodeComponent in Get-ChildItem $script:VSCodeOutput) {
261+
if (-not $includedDlls.Contains($vscodeComponent.Name)) {
344262
Copy-Item -Path $vscodeComponent.FullName -Destination $psesVSCodeBinOutputPath -Force
345263
}
346264
}
347265
}
348266

349267
task RestorePsesModules -After Build {
350268
$submodulePath = (Resolve-Path $PsesSubmodulePath).Path + [IO.Path]::DirectorySeparatorChar
351-
Write-Host "`nRestoring EditorServices modules..."
269+
Write-Host "Restoring EditorServices modules..."
352270

353271
# Read in the modules.json file as a hashtable so it can be splatted
354272
$moduleInfos = @{}
@@ -398,14 +316,12 @@ task RestorePsesModules -After Build {
398316

399317
Save-Module @splatParameters
400318
}
401-
402-
Write-Host "`n"
403319
}
404320

405-
task BuildCmdletHelp {
321+
Task BuildCmdletHelp -After LayoutModule {
406322
New-ExternalHelp -Path $PSScriptRoot\module\docs -OutputPath $PSScriptRoot\module\PowerShellEditorServices\Commands\en-US -Force
407323
New-ExternalHelp -Path $PSScriptRoot\module\PowerShellEditorServices.VSCode\docs -OutputPath $PSScriptRoot\module\PowerShellEditorServices.VSCode\en-US -Force
408324
}
409325

410326
# The default task is to run the entire CI build
411-
task . Clean, Build, Test, BuildCmdletHelp
327+
task . Clean, Build, Test

tools/azurePipelinesBuild.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if ($IsWindows -or $PSVersionTable.PSVersion.Major -lt 6) {
1717
Update-Help -Force -ErrorAction SilentlyContinue
1818

1919
# Needed for build and docs gen.
20-
Install-Module -Name InvokeBuild -MaximumVersion 5.1.0 -Scope CurrentUser -Force
21-
Install-Module -Name PlatyPS -RequiredVersion 0.9.0 -Scope CurrentUser -Force
20+
Install-Module -Name InvokeBuild -RequiredVersion 5.9.7 -Scope CurrentUser -Force
21+
Install-Module -Name platyPS -RequiredVersion 0.14.2 -Scope CurrentUser -Force
2222

2323
Invoke-Build -Configuration Release

0 commit comments

Comments
 (0)