6
6
# Requires -Modules @ {ModuleName = " InvokeBuild" ;ModuleVersion = " 3.2.1" }
7
7
8
8
$script :IsCIBuild = $env: APPVEYOR -ne $null
9
+ $script :IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq " Core" -and ! $IsWindows
10
+ $script :TargetFrameworksParam = " /p:TargetFrameworks=\`" $ ( if (! $script :IsUnix ) { " net451;" }) netstandard1.6\`" "
11
+
12
+ if ($PSVersionTable.PSEdition -ne " Core" ) {
13
+ Add-Type - Assembly System.IO.Compression.FileSystem - ErrorAction SilentlyContinue
14
+ }
9
15
10
16
task SetupDotNet - Before Restore, Clean , Build, BuildHost, Test, TestPowerShellApi {
11
17
@@ -15,7 +21,7 @@ task SetupDotNet -Before Restore, Clean, Build, BuildHost, Test, TestPowerShellA
15
21
$requiredDotnetVersion = " 1.0.0-preview4-004233"
16
22
$needsInstall = $true
17
23
$dotnetPath = " $PSScriptRoot /.dotnet"
18
- $dotnetExePath = " $dotnetPath /dotnet.exe"
24
+ $dotnetExePath = if ( $ script :IsUnix ) { " $dotnetPath /dotnet" } else { " $dotnetPath /dotnet .exe" }
19
25
20
26
if (Test-Path $dotnetExePath ) {
21
27
$script :dotnetExe = $dotnetExePath
@@ -36,11 +42,21 @@ task SetupDotNet -Before Restore, Clean, Build, BuildHost, Test, TestPowerShellA
36
42
37
43
Write-Host " `n ### Installing .NET CLI $requiredDotnetVersion ...`n " - ForegroundColor Green
38
44
45
+ # The install script is platform-specific
46
+ $installScriptExt = if ($script :IsUnix ) { " sh" } else { " ps1" }
47
+
39
48
# Download the official installation script and run it
40
- $installScriptPath = " $ ( $env: TEMP ) \dotnet-install.ps1"
41
- Invoke-WebRequest " https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview4/scripts/obtain/dotnet-install.ps1" - OutFile $installScriptPath
42
- $env: DOTNET_INSTALL_DIR = " $PSScriptRoot \.dotnet"
43
- & $installScriptPath - Version $requiredDotnetVersion - InstallDir " $env: DOTNET_INSTALL_DIR "
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"
52
+
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
+ }
44
60
45
61
Write-Host " `n ### Installation complete." - ForegroundColor Green
46
62
$script :dotnetExe = $dotnetExePath
@@ -60,11 +76,11 @@ task SetupDotNet -Before Restore, Clean, Build, BuildHost, Test, TestPowerShellA
60
76
}
61
77
62
78
task Restore {
63
- exec { & dotnet restore }
79
+ exec { & $ script :dotnetExe restore }
64
80
}
65
81
66
82
task Clean {
67
- exec { & dotnet clean }
83
+ exec { & $ script :dotnetExe clean }
68
84
Get-ChildItem - Recurse src\* .nupkg | Remove-Item - Force - ErrorAction Ignore
69
85
Get-ChildItem module\* .zip | Remove-Item - Force - ErrorAction Ignore
70
86
}
@@ -88,58 +104,59 @@ task GetProductVersion -Before PackageNuGet, PackageModule, UploadArtifacts {
88
104
89
105
function BuildForPowerShellVersion ($version ) {
90
106
# Restore packages for the specified version
91
- exec { & dotnet restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -- / p:PowerShellVersion= $version }
107
+ exec { & $ script :dotnetExe restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -- / p:PowerShellVersion= $version }
92
108
93
109
Write-Host - ForegroundColor Green " `n ### Testing API usage for PowerShell $version ...`n "
94
- exec { & dotnet build -f net451 .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -- / p:PowerShellVersion= $version }
110
+ exec { & $ script :dotnetExe build -f net451 .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -- / p:PowerShellVersion= $version }
95
111
}
96
112
97
- task TestPowerShellApi {
113
+ task TestPowerShellApi - If { ! $ script :IsUnix } {
98
114
BuildForPowerShellVersion v3
99
115
BuildForPowerShellVersion v4
100
116
BuildForPowerShellVersion v5r1
101
117
102
118
# Do a final restore to put everything back to normal
103
- exec { & dotnet restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj }
119
+ exec { & $ script :dotnetExe restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj }
104
120
}
105
121
106
122
task BuildHost {
107
- exec { & dotnet build - c $Configuration .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj }
123
+ exec { & $ script :dotnetExe build - c $Configuration .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj -- $ script :TargetFrameworksParam }
108
124
}
109
125
110
126
task Build {
111
- exec { & dotnet build - c $Configuration .\PowerShellEditorServices.sln }
127
+ exec { & $ script :dotnetExe build - c $Configuration .\PowerShellEditorServices.sln -- $ script :TargetFrameworksParam }
112
128
}
113
129
114
- task Test {
130
+ task Test - If { ! $ script :IsUnix } {
115
131
$testParams = @ {}
116
132
if ($env: APPVEYOR -ne $null ) {
117
133
$testParams = @ {" l" = " appveyor" }
118
134
}
119
135
120
- exec { & dotnet test - c $Configuration @testParams .\test\PowerShellEditorServices.Test\PowerShellEditorServices.Test.csproj }
121
- exec { & dotnet test - c $Configuration @testParams .\test\PowerShellEditorServices.Test.Protocol\PowerShellEditorServices.Test.Protocol.csproj }
122
- exec { & dotnet test - c $Configuration @testParams .\test\PowerShellEditorServices.Test.Host\PowerShellEditorServices.Test.Host.csproj }
136
+ exec { & $ script :dotnetExe test - c $Configuration @testParams .\test\PowerShellEditorServices.Test\PowerShellEditorServices.Test.csproj }
137
+ exec { & $ script :dotnetExe test - c $Configuration @testParams .\test\PowerShellEditorServices.Test.Protocol\PowerShellEditorServices.Test.Protocol.csproj }
138
+ exec { & $ script :dotnetExe test - c $Configuration @testParams .\test\PowerShellEditorServices.Test.Host\PowerShellEditorServices.Test.Host.csproj }
123
139
}
124
140
125
141
task LayoutModule - After Build, BuildHost {
126
142
New-Item - Force $PSScriptRoot \module\PowerShellEditorServices\bin\ - Type Directory | Out-Null
127
143
New-Item - Force $PSScriptRoot \module\PowerShellEditorServices\bin\Desktop - Type Directory | Out-Null
128
144
New-Item - Force $PSScriptRoot \module\PowerShellEditorServices\bin\Core - Type Directory | Out-Null
129
145
130
- Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices.Host\bin\$Configuration \net451\* - Filter Microsoft.PowerShell.EditorServices* .dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Desktop\
131
- Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices.Host\bin\$Configuration \net451\Newtonsoft.Json.dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Desktop\
146
+ if (! $script :IsUnix ) {
147
+ Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices.Host\bin\$Configuration \net451\* - Filter Microsoft.PowerShell.EditorServices* .dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Desktop\
148
+ Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices.Host\bin\$Configuration \net451\Newtonsoft.Json.dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Desktop\
149
+ }
132
150
Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices.Host\bin\$Configuration \netstandard1.6 \* - Filter Microsoft.PowerShell.EditorServices* .dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Core\
133
151
}
134
152
135
153
task PackageNuGet {
136
- exec { & dotnet pack - c $Configuration -- version- suffix $script :VersionSuffix .\src\PowerShellEditorServices\PowerShellEditorServices.csproj }
137
- exec { & dotnet pack - c $Configuration -- version- suffix $script :VersionSuffix .\src\PowerShellEditorServices.Protocol\PowerShellEditorServices.Protocol.csproj }
138
- exec { & dotnet pack - c $Configuration -- version- suffix $script :VersionSuffix .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj }
154
+ exec { & $ script :dotnetExe pack - c $Configuration -- version- suffix $script :VersionSuffix .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -- $ script :TargetFrameworksParam }
155
+ exec { & $ script :dotnetExe pack - c $Configuration -- version- suffix $script :VersionSuffix .\src\PowerShellEditorServices.Protocol\PowerShellEditorServices.Protocol.csproj -- $ script :TargetFrameworksParam }
156
+ exec { & $ script :dotnetExe pack - c $Configuration -- version- suffix $script :VersionSuffix .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj -- $ script :TargetFrameworksParam }
139
157
}
140
158
141
159
task PackageModule {
142
- Add-Type - Assembly System.IO.Compression.FileSystem - ErrorAction Ignore
143
160
[System.IO.Compression.ZipFile ]::CreateFromDirectory(
144
161
" $PSScriptRoot /module/PowerShellEditorServices" ,
145
162
" $PSScriptRoot /module/PowerShellEditorServices-$ ( $script :FullVersion ) .zip" ,
@@ -159,7 +176,6 @@ task UploadArtifacts -If ($script:IsCIBuild) {
159
176
task UploadTestLogs - If ($script :IsCIBuild ) {
160
177
$testLogsZipPath = " $PSScriptRoot /TestLogs.zip"
161
178
162
- Add-Type - Assembly System.IO.Compression.FileSystem - ErrorAction Ignore
163
179
[System.IO.Compression.ZipFile ]::CreateFromDirectory(
164
180
" $PSScriptRoot /test/PowerShellEditorServices.Test.Host/bin/$Configuration /net451/logs" ,
165
181
$testLogsZipPath )
0 commit comments