@@ -13,54 +13,66 @@ if ($PSVersionTable.PSEdition -ne "Core") {
1313 Add-Type - Assembly System.IO.Compression.FileSystem - ErrorAction SilentlyContinue
1414}
1515
16- task SetupDotNet - Before Restore, Clean , Build, BuildHost, Test, TestPowerShellApi {
16+ task SetupDotNet - Before Restore, Clean , Build, BuildHost, Test, TestPowerShellApi, PackageNuGet {
1717
1818 # Bail out early if we've already found the exe path
1919 if ($script :dotnetExe -ne $null ) { return }
2020
21- $requiredDotnetVersion = " 1.0.0-preview4-004233"
21+ # Fetch the SDK version from global.json
22+ $globalJson = Get-Content $PSScriptRoot / global.json | ConvertFrom-Json
23+ $requiredSdkVersion = $globalJson.sdk.version
24+
25+ # Alternative versions:
26+ # "version": "1.0.0-rc4-004598"
27+ # "version": "1.0.0-rc3-004517"
28+ # "version": "1.0.0-preview4-004233"
29+
2230 $needsInstall = $true
2331 $dotnetPath = " $PSScriptRoot /.dotnet"
2432 $dotnetExePath = if ($script :IsUnix ) { " $dotnetPath /dotnet" } else { " $dotnetPath /dotnet.exe" }
33+ $originalDotNetExePath = $dotnetExePath
2534
26- if (Test-Path $dotnetExePath ) {
27- $script :dotnetExe = $dotnetExePath
28- }
29- else {
35+ if (! (Test-Path $dotnetExePath )) {
3036 $installedDotnet = Get-Command dotnet - ErrorAction Ignore
3137 if ($installedDotnet ) {
3238 $dotnetExePath = $installedDotnet.Source
33-
34- exec {
35- if ((& $dotnetExePath -- version) -eq $requiredDotnetVersion ) {
36- $script :dotnetExe = $dotnetExePath
37- }
38- }
3939 }
40+ else {
41+ $dotnetExePath = $null
42+ }
43+ }
4044
41- if ($script :dotnetExe -eq $null ) {
45+ # Make sure the dotnet we found is the right version
46+ if ($dotnetExePath -and (& $dotnetExePath -- version) -eq $requiredSdkVersion ) {
47+ $script :dotnetExe = $dotnetExePath
48+ }
49+ else {
50+ # Clear the path so that we invoke installation
51+ $script :dotnetExe = $null
52+ }
4253
43- Write-Host " `n ### Installing .NET CLI $requiredDotnetVersion ... `n " - ForegroundColor Green
54+ if ( $ script :dotnetExe -eq $null ) {
4455
45- # The install script is platform-specific
46- $installScriptExt = if ($script :IsUnix ) { " sh" } else { " ps1" }
56+ Write-Host " `n ### Installing .NET CLI $requiredSdkVersion ...`n " - ForegroundColor Green
4757
48- # Download the official installation script and run it
49- $installScriptPath = " $ ( [System.IO.Path ]::GetTempPath()) dotnet-install.$installScriptExt "
50- Invoke-WebRequest " https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview4/scripts/obtain/dotnet-install.$installScriptExt " - OutFile $installScriptPath
51- $env: DOTNET_INSTALL_DIR = " $PSScriptRoot /.dotnet"
58+ # The install script is platform-specific
59+ $installScriptExt = if ($script :IsUnix ) { " sh" } else { " ps1" }
5260
53- if (! $script :IsUnix ) {
54- & $installScriptPath - Version $requiredDotnetVersion - InstallDir " $env: DOTNET_INSTALL_DIR "
55- }
56- else {
57- & / bin/ bash $installScriptPath - Version $requiredDotnetVersion - InstallDir " $env: DOTNET_INSTALL_DIR "
58- $env: PATH = $dotnetExeDir + [System.IO.Path ]::PathSeparator + $env: PATH
59- }
61+ # Download the official installation script and run it
62+ $installScriptPath = " $ ( [System.IO.Path ]::GetTempPath()) dotnet-install.$installScriptExt "
63+ Invoke-WebRequest " https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview4/scripts/obtain/dotnet-install.$installScriptExt " - OutFile $installScriptPath
64+ $env: DOTNET_INSTALL_DIR = " $PSScriptRoot /.dotnet"
6065
61- Write-Host " `n ### Installation complete." - ForegroundColor Green
62- $script :dotnetExe = $dotnetExePath
66+ if (! $script :IsUnix ) {
67+ & $installScriptPath - Version $requiredSdkVersion - InstallDir " $env: DOTNET_INSTALL_DIR "
68+ }
69+ else {
70+ & / bin/ bash $installScriptPath - Version $requiredSdkVersion - InstallDir " $env: DOTNET_INSTALL_DIR "
71+ $env: PATH = $dotnetExeDir + [System.IO.Path ]::PathSeparator + $env: PATH
6372 }
73+
74+ Write-Host " `n ### Installation complete." - ForegroundColor Green
75+ $script :dotnetExe = $originalDotnetExePath
6476 }
6577
6678 # This variable is used internally by 'dotnet' to know where it's installed
@@ -104,10 +116,10 @@ task GetProductVersion -Before PackageNuGet, PackageModule, UploadArtifacts {
104116
105117function BuildForPowerShellVersion ($version ) {
106118 # Restore packages for the specified version
107- exec { & $script :dotnetExe restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -- / p:PowerShellVersion= $version }
119+ exec { & $script :dotnetExe restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj / p:PowerShellVersion= $version }
108120
109121 Write-Host - ForegroundColor Green " `n ### Testing API usage for PowerShell $version ...`n "
110- exec { & $script :dotnetExe build -f net451 .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -- / p:PowerShellVersion= $version }
122+ exec { & $script :dotnetExe build -f net451 .\src\PowerShellEditorServices\PowerShellEditorServices.csproj / p:PowerShellVersion= $version }
111123}
112124
113125task TestPowerShellApi - If { ! $script :IsUnix } {
@@ -120,17 +132,17 @@ task TestPowerShellApi -If { !$script:IsUnix } {
120132}
121133
122134task BuildHost {
123- exec { & $script :dotnetExe build - c $Configuration .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj -- $script :TargetFrameworksParam }
135+ exec { & $script :dotnetExe build - c $Configuration .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj $script :TargetFrameworksParam }
124136}
125137
126138task Build {
127- exec { & $script :dotnetExe build - c $Configuration .\PowerShellEditorServices.sln -- $script :TargetFrameworksParam }
139+ exec { & $script :dotnetExe build - c $Configuration .\PowerShellEditorServices.sln $script :TargetFrameworksParam }
128140}
129141
130142task Test - If { ! $script :IsUnix } {
131- exec { & $script :dotnetExe test - c $Configuration .\test\PowerShellEditorServices.Test\PowerShellEditorServices.Test.csproj }
132- exec { & $script :dotnetExe test - c $Configuration .\test\PowerShellEditorServices.Test.Protocol\PowerShellEditorServices.Test.Protocol.csproj }
133- exec { & $script :dotnetExe test - c $Configuration .\test\PowerShellEditorServices.Test.Host\PowerShellEditorServices.Test.Host.csproj }
143+ exec { & $script :dotnetExe test - c $Configuration -f net451 .\test\PowerShellEditorServices.Test\PowerShellEditorServices.Test.csproj }
144+ exec { & $script :dotnetExe test - c $Configuration -f net451 .\test\PowerShellEditorServices.Test.Protocol\PowerShellEditorServices.Test.Protocol.csproj }
145+ exec { & $script :dotnetExe test - c $Configuration -f net451 .\test\PowerShellEditorServices.Test.Host\PowerShellEditorServices.Test.Host.csproj }
134146}
135147
136148task LayoutModule - After Build, BuildHost {
@@ -146,9 +158,9 @@ task LayoutModule -After Build, BuildHost {
146158}
147159
148160task PackageNuGet {
149- exec { & $script :dotnetExe pack - c $Configuration -- version- suffix $script :VersionSuffix .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -- $script :TargetFrameworksParam }
150- exec { & $script :dotnetExe pack - c $Configuration -- version- suffix $script :VersionSuffix .\src\PowerShellEditorServices.Protocol\PowerShellEditorServices.Protocol.csproj -- $script :TargetFrameworksParam }
151- exec { & $script :dotnetExe pack - c $Configuration -- version- suffix $script :VersionSuffix .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj -- $script :TargetFrameworksParam }
161+ exec { & $script :dotnetExe pack - c $Configuration -- version- suffix $script :VersionSuffix .\src\PowerShellEditorServices\PowerShellEditorServices.csproj $script :TargetFrameworksParam }
162+ exec { & $script :dotnetExe pack - c $Configuration -- version- suffix $script :VersionSuffix .\src\PowerShellEditorServices.Protocol\PowerShellEditorServices.Protocol.csproj $script :TargetFrameworksParam }
163+ exec { & $script :dotnetExe pack - c $Configuration -- version- suffix $script :VersionSuffix .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj $script :TargetFrameworksParam }
152164}
153165
154166task PackageModule {
0 commit comments