@@ -52,84 +52,18 @@ if (Get-Command git -ErrorAction SilentlyContinue) {
5252 git update-index -- assume- unchanged " $PSScriptRoot /src/PowerShellEditorServices.Hosting/BuildInfo.cs"
5353}
5454
55- function Install-Dotnet {
56- param (
57- [string []]$Channel ,
58- [switch ]$Runtime
59- )
60-
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 }
55+ task FindDotNet {
56+ assert (Get-Command dotnet - ErrorAction SilentlyContinue) " dotnet not found, please install it: https://aka.ms/dotnet-cli"
57+ assert ([Version ](dotnet -- version) -ge [Version ](" 6.0" )) " .NET SDK 6.0 or higher is required, please update it: https://aka.ms/dotnet-cli"
58+
59+ # Anywhere other than on a Mac with an M1 processor, we additionally
60+ # need the .NET 3.1 runtime for our netcoreapp3.1 framework.
61+ if (! $script :IsAppleM1 ) {
62+ $runtimes = dotnet -- list- runtimes
63+ assert ($runtimes -match " Microsoft.NETCore.App 3.1" ) " .NET Runtime 3.1 required but not found!"
10164 }
10265
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
66+ Write-Host " Using dotnet v$ ( dotnet -- version) at path $ ( (Get-Command dotnet).Source) " - ForegroundColor Green
13367}
13468
13569task BinClean {
@@ -138,9 +72,8 @@ task BinClean {
13872 Remove-Item $PSScriptRoot \module\PowerShellEditorServices.VSCode\bin - Recurse - Force - ErrorAction Ignore
13973}
14074
141- task Clean BinClean, {
142- exec { & $script :dotnetExe restore }
143- exec { & $script :dotnetExe clean }
75+ task Clean FindDotNet, BinClean, {
76+ exec { & dotnet clean }
14477 Get-ChildItem - Recurse $PSScriptRoot \src\* .nupkg | Remove-Item - Force - ErrorAction Ignore
14578 Get-ChildItem $PSScriptRoot \PowerShellEditorServices* .zip | Remove-Item - Force - ErrorAction Ignore
14679 Get-ChildItem $PSScriptRoot \module\PowerShellEditorServices\Commands\en- US\*- help.xml | Remove-Item - Force - ErrorAction Ignore
@@ -155,7 +88,7 @@ task Clean BinClean,{
15588 }
15689}
15790
158- task CreateBuildInfo - Before Build {
91+ task CreateBuildInfo {
15992 $buildVersion = " <development-build>"
16093 $buildOrigin = " Development"
16194 $buildCommit = git rev- parse HEAD
@@ -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 }
0 commit comments