Skip to content

Commit 0053167

Browse files
committed
Add net8.0 to build script, clean up test tasks and fix PSModulePath bug
We've known inheriting that environment variable breaks stuff, but now it breaks tests too.
1 parent bf24627 commit 0053167

File tree

1 file changed

+78
-33
lines changed

1 file changed

+78
-33
lines changed

PowerShellEditorServices.build.ps1

+78-33
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,18 @@ $script:IsArm64 = -not $script:IsNix -and @("ARM64") -contains $env:PROCESSOR_AR
4848
$script:BuildInfoPath = [System.IO.Path]::Combine($PSScriptRoot, "src", "PowerShellEditorServices.Hosting", "BuildInfo.cs")
4949
$script:PsesCommonProps = [xml](Get-Content -Raw "$PSScriptRoot/PowerShellEditorServices.Common.props")
5050

51-
$script:NetRuntime = @{
51+
$script:NetFramework = @{
52+
PS51 = 'net462'
5253
PS72 = 'net6.0'
5354
PS73 = 'net7.0'
54-
Desktop = 'net462'
55+
PS74 = 'net8.0'
5556
Standard = 'netstandard2.0'
5657
}
5758

58-
$script:HostCoreOutput = "$PSScriptRoot/src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetRuntime.PS72)/publish"
59-
$script:HostDeskOutput = "$PSScriptRoot/src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetRuntime.Desktop)/publish"
60-
$script:PsesOutput = "$PSScriptRoot/src/PowerShellEditorServices/bin/$Configuration/$($script:NetRuntime.Standard)/publish"
61-
$script:VSCodeOutput = "$PSScriptRoot/src/PowerShellEditorServices.VSCode/bin/$Configuration/$($script:NetRuntime.Standard)/publish"
59+
$script:HostCoreOutput = "$PSScriptRoot/src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetFramework.PS72)/publish"
60+
$script:HostDeskOutput = "$PSScriptRoot/src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetFramework.PS51)/publish"
61+
$script:PsesOutput = "$PSScriptRoot/src/PowerShellEditorServices/bin/$Configuration/$($script:NetFramework.Standard)/publish"
62+
$script:VSCodeOutput = "$PSScriptRoot/src/PowerShellEditorServices.VSCode/bin/$Configuration/$($script:NetFramework.Standard)/publish"
6263

6364
if (Get-Command git -ErrorAction SilentlyContinue) {
6465
# ignore changes to this file
@@ -157,63 +158,103 @@ namespace Microsoft.PowerShell.EditorServices.Hosting
157158
}
158159

159160
Task SetupHelpForTests {
160-
if (-not (Get-Help Microsoft.PowerShell.Management\Get-Process).Description) {
161-
Write-Host "Updating help for tests."
162-
Update-Help -Module Microsoft.PowerShell.Management,Microsoft.PowerShell.Utility -Force -Scope CurrentUser
163-
}
161+
# TODO: Check if it must be updated in a compatible way!
162+
Write-Host "Updating help for tests."
163+
Update-Help -Module Microsoft.PowerShell.Management,Microsoft.PowerShell.Utility -Force -Scope CurrentUser
164164
}
165165

166166
Task Build FindDotNet, CreateBuildInfo, {
167-
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -f $script:NetRuntime.Standard }
168-
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.PS72 }
167+
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -f $script:NetFramework.Standard }
168+
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetFramework.PS72 }
169169

170170
if (-not $script:IsNix) {
171-
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.Desktop }
171+
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetFramework.PS51 }
172172
}
173173

174174
# Build PowerShellEditorServices.VSCode module
175-
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices.VSCode\PowerShellEditorServices.VSCode.csproj -f $script:NetRuntime.Standard }
175+
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices.VSCode\PowerShellEditorServices.VSCode.csproj -f $script:NetFramework.Standard }
176176
}
177177

178-
Task Test TestServer, TestE2E, TestConstrainedLanguageMode
178+
# The concise set of tests (for pull requests)
179+
Task Test TestPS74, TestE2EPwsh, TestPS51, TestE2EPowerShell
179180

180-
Task TestServer SetupHelpForTests, TestServerWinPS, TestServerPS72, TestServerPS73
181+
# Every combination of tests (for main branch)
182+
Task TestFull Test, TestPS73, TestPS72, TestE2EPwshCLM, TestE2EPowerShellCLM
181183

182-
Task TestE2E SetupHelpForTests, TestE2EPwsh, TestE2EWinPS
184+
Task TestPS74 Build, SetupHelpForTests, {
185+
Set-Location .\test\PowerShellEditorServices.Test\
186+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
187+
}
183188

184-
Task TestServerWinPS -If (-not $script:IsNix) Build, {
189+
Task TestPS73 Build, SetupHelpForTests, {
185190
Set-Location .\test\PowerShellEditorServices.Test\
186-
# TODO: See https://github.com/dotnet/sdk/issues/18353 for x64 test host
187-
# that is debuggable! If architecture is added, the assembly path gets an
188-
# additional folder, necesstiating fixes to find the commands definition
189-
# file and test files.
190-
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.Desktop }
191+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS73 }
191192
}
192193

193-
Task TestServerPS72 Build, {
194+
Task TestPS72 Build, SetupHelpForTests, {
194195
Set-Location .\test\PowerShellEditorServices.Test\
195-
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS72 }
196+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS72 }
196197
}
197198

198-
Task TestServerPS73 Build, {
199+
Task TestPS51 -If (-not $script:IsNix) Build, SetupHelpForTests, {
199200
Set-Location .\test\PowerShellEditorServices.Test\
200-
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS73 }
201+
# TODO: See https://github.com/dotnet/sdk/issues/18353 for x64 test host
202+
# that is debuggable! If architecture is added, the assembly path gets an
203+
# additional folder, necessitating fixes to find the commands definition
204+
# file and test files.
205+
try {
206+
# TODO: See https://github.com/PowerShell/vscode-powershell/issues/3886
207+
# Inheriting the module path for powershell.exe breaks things!
208+
$originalModulePath = $env:PSModulePath
209+
$env:PSModulePath = ""
210+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS51 }
211+
} finally {
212+
$env:PSModulePath = $originalModulePath
213+
}
201214
}
202215

203-
Task TestE2EPwsh Build, {
216+
# NOTE: The framework for the E2E tests applies to the mock client, and so
217+
# should just be the latest supported framework.
218+
Task TestE2EPwsh Build, SetupHelpForTests, {
204219
Set-Location .\test\PowerShellEditorServices.Test.E2E\
205220
$env:PWSH_EXE_NAME = "pwsh"
206-
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS73 }
221+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
207222
}
208223

209-
Task TestE2EWinPS -If (-not $script:IsNix) Build, {
224+
Task TestE2EPowerShell -If (-not $script:IsNix) Build, SetupHelpForTests, {
210225
Set-Location .\test\PowerShellEditorServices.Test.E2E\
211226
$env:PWSH_EXE_NAME = "powershell"
212-
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS73 }
227+
try {
228+
# TODO: See https://github.com/PowerShell/vscode-powershell/issues/3886
229+
# Inheriting the module path for powershell.exe breaks things!
230+
$originalModulePath = $env:PSModulePath
231+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
232+
} finally {
233+
$env:PSModulePath = $originalModulePath
234+
}
235+
}
236+
237+
Task TestE2EPwshCLM -If (-not $script:IsNix) Build, SetupHelpForTests, {
238+
Set-Location .\test\PowerShellEditorServices.Test.E2E\
239+
$env:PWSH_EXE_NAME = "pwsh"
240+
241+
if (-not [Security.Principal.WindowsIdentity]::GetCurrent().Owner.IsWellKnown("BuiltInAdministratorsSid")) {
242+
Write-Warning "Skipping Constrained Language Mode tests as they must be ran in an elevated process."
243+
return
244+
}
245+
246+
try {
247+
Write-Host "Running end-to-end tests in Constrained Language Mode."
248+
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", "0x80000007", [System.EnvironmentVariableTarget]::Machine)
249+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
250+
} finally {
251+
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", $null, [System.EnvironmentVariableTarget]::Machine)
252+
}
213253
}
214254

215-
Task TestConstrainedLanguageMode -If (-not $script:IsNix) Build, {
255+
Task TestE2EPowerShellCLM -If (-not $script:IsNix) Build, SetupHelpForTests, {
216256
Set-Location .\test\PowerShellEditorServices.Test.E2E\
257+
$env:PWSH_EXE_NAME = "powershell"
217258

218259
if (-not [Security.Principal.WindowsIdentity]::GetCurrent().Owner.IsWellKnown("BuiltInAdministratorsSid")) {
219260
Write-Warning "Skipping Constrained Language Mode tests as they must be ran in an elevated process."
@@ -223,9 +264,13 @@ Task TestConstrainedLanguageMode -If (-not $script:IsNix) Build, {
223264
try {
224265
Write-Host "Running end-to-end tests in Constrained Language Mode."
225266
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", "0x80000007", [System.EnvironmentVariableTarget]::Machine)
226-
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS73 }
267+
# TODO: See https://github.com/PowerShell/vscode-powershell/issues/3886
268+
# Inheriting the module path for powershell.exe breaks things!
269+
$originalModulePath = $env:PSModulePath
270+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
227271
} finally {
228272
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", $null, [System.EnvironmentVariableTarget]::Machine)
273+
$env:PSModulePath = $originalModulePath
229274
}
230275
}
231276

0 commit comments

Comments
 (0)