@@ -13,54 +13,66 @@ if ($PSVersionTable.PSEdition -ne "Core") {
13
13
Add-Type - Assembly System.IO.Compression.FileSystem - ErrorAction SilentlyContinue
14
14
}
15
15
16
- task SetupDotNet - Before Restore, Clean , Build, BuildHost, Test, TestPowerShellApi {
16
+ task SetupDotNet - Before Restore, Clean , Build, BuildHost, Test, TestPowerShellApi, PackageNuGet {
17
17
18
18
# Bail out early if we've already found the exe path
19
19
if ($script :dotnetExe -ne $null ) { return }
20
20
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
+
22
30
$needsInstall = $true
23
31
$dotnetPath = " $PSScriptRoot /.dotnet"
24
32
$dotnetExePath = if ($script :IsUnix ) { " $dotnetPath /dotnet" } else { " $dotnetPath /dotnet.exe" }
33
+ $originalDotNetExePath = $dotnetExePath
25
34
26
- if (Test-Path $dotnetExePath ) {
27
- $script :dotnetExe = $dotnetExePath
28
- }
29
- else {
35
+ if (! (Test-Path $dotnetExePath )) {
30
36
$installedDotnet = Get-Command dotnet - ErrorAction Ignore
31
37
if ($installedDotnet ) {
32
38
$dotnetExePath = $installedDotnet.Source
33
-
34
- exec {
35
- if ((& $dotnetExePath -- version) -eq $requiredDotnetVersion ) {
36
- $script :dotnetExe = $dotnetExePath
37
- }
38
- }
39
39
}
40
+ else {
41
+ $dotnetExePath = $null
42
+ }
43
+ }
40
44
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
+ }
42
53
43
- Write-Host " `n ### Installing .NET CLI $requiredDotnetVersion ... `n " - ForegroundColor Green
54
+ if ( $ script :dotnetExe -eq $null ) {
44
55
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
47
57
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" }
52
60
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"
60
65
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
63
72
}
73
+
74
+ Write-Host " `n ### Installation complete." - ForegroundColor Green
75
+ $script :dotnetExe = $originalDotnetExePath
64
76
}
65
77
66
78
# This variable is used internally by 'dotnet' to know where it's installed
@@ -104,10 +116,10 @@ task GetProductVersion -Before PackageNuGet, PackageModule, UploadArtifacts {
104
116
105
117
function BuildForPowerShellVersion ($version ) {
106
118
# 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 }
108
120
109
121
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 }
111
123
}
112
124
113
125
task TestPowerShellApi - If { ! $script :IsUnix } {
@@ -120,17 +132,17 @@ task TestPowerShellApi -If { !$script:IsUnix } {
120
132
}
121
133
122
134
task 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 }
124
136
}
125
137
126
138
task Build {
127
- exec { & $script :dotnetExe build - c $Configuration .\PowerShellEditorServices.sln -- $script :TargetFrameworksParam }
139
+ exec { & $script :dotnetExe build - c $Configuration .\PowerShellEditorServices.sln $script :TargetFrameworksParam }
128
140
}
129
141
130
142
task 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 }
134
146
}
135
147
136
148
task LayoutModule - After Build, BuildHost {
@@ -146,9 +158,9 @@ task LayoutModule -After Build, BuildHost {
146
158
}
147
159
148
160
task 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 }
152
164
}
153
165
154
166
task PackageModule {
0 commit comments