66# Requires -Modules @ {ModuleName = " InvokeBuild" ;ModuleVersion = " 3.2.1" }
77
88$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+ }
915
1016task SetupDotNet - Before Restore, Clean , Build, BuildHost, Test, TestPowerShellApi {
1117
@@ -15,7 +21,7 @@ task SetupDotNet -Before Restore, Clean, Build, BuildHost, Test, TestPowerShellA
1521 $requiredDotnetVersion = " 1.0.0-preview4-004233"
1622 $needsInstall = $true
1723 $dotnetPath = " $PSScriptRoot /.dotnet"
18- $dotnetExePath = " $dotnetPath /dotnet.exe"
24+ $dotnetExePath = if ( $ script :IsUnix ) { " $dotnetPath /dotnet" } else { " $dotnetPath /dotnet .exe" }
1925
2026 if (Test-Path $dotnetExePath ) {
2127 $script :dotnetExe = $dotnetExePath
@@ -36,11 +42,21 @@ task SetupDotNet -Before Restore, Clean, Build, BuildHost, Test, TestPowerShellA
3642
3743 Write-Host " `n ### Installing .NET CLI $requiredDotnetVersion ...`n " - ForegroundColor Green
3844
45+ # The install script is platform-specific
46+ $installScriptExt = if ($script :IsUnix ) { " sh" } else { " ps1" }
47+
3948 # 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+ }
4460
4561 Write-Host " `n ### Installation complete." - ForegroundColor Green
4662 $script :dotnetExe = $dotnetExePath
@@ -60,11 +76,11 @@ task SetupDotNet -Before Restore, Clean, Build, BuildHost, Test, TestPowerShellA
6076}
6177
6278task Restore {
63- exec { & dotnet restore }
79+ exec { & $ script :dotnetExe restore }
6480}
6581
6682task Clean {
67- exec { & dotnet clean }
83+ exec { & $ script :dotnetExe clean }
6884 Get-ChildItem - Recurse src\* .nupkg | Remove-Item - Force - ErrorAction Ignore
6985 Get-ChildItem module\* .zip | Remove-Item - Force - ErrorAction Ignore
7086}
@@ -88,58 +104,59 @@ task GetProductVersion -Before PackageNuGet, PackageModule, UploadArtifacts {
88104
89105function BuildForPowerShellVersion ($version ) {
90106 # 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 }
92108
93109 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 }
95111}
96112
97- task TestPowerShellApi {
113+ task TestPowerShellApi - If { ! $ script :IsUnix } {
98114 BuildForPowerShellVersion v3
99115 BuildForPowerShellVersion v4
100116 BuildForPowerShellVersion v5r1
101117
102118 # 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 }
104120}
105121
106122task 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 }
108124}
109125
110126task Build {
111- exec { & dotnet build - c $Configuration .\PowerShellEditorServices.sln }
127+ exec { & $ script :dotnetExe build - c $Configuration .\PowerShellEditorServices.sln -- $ script :TargetFrameworksParam }
112128}
113129
114- task Test {
130+ task Test - If { ! $ script :IsUnix } {
115131 $testParams = @ {}
116132 if ($env: APPVEYOR -ne $null ) {
117133 $testParams = @ {" l" = " appveyor" }
118134 }
119135
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 }
123139}
124140
125141task LayoutModule - After Build, BuildHost {
126142 New-Item - Force $PSScriptRoot \module\PowerShellEditorServices\bin\ - Type Directory | Out-Null
127143 New-Item - Force $PSScriptRoot \module\PowerShellEditorServices\bin\Desktop - Type Directory | Out-Null
128144 New-Item - Force $PSScriptRoot \module\PowerShellEditorServices\bin\Core - Type Directory | Out-Null
129145
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+ }
132150 Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices.Host\bin\$Configuration \netstandard1.6 \* - Filter Microsoft.PowerShell.EditorServices* .dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Core\
133151}
134152
135153task 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 }
139157}
140158
141159task PackageModule {
142- Add-Type - Assembly System.IO.Compression.FileSystem - ErrorAction Ignore
143160 [System.IO.Compression.ZipFile ]::CreateFromDirectory(
144161 " $PSScriptRoot /module/PowerShellEditorServices" ,
145162 " $PSScriptRoot /module/PowerShellEditorServices-$ ( $script :FullVersion ) .zip" ,
@@ -159,7 +176,6 @@ task UploadArtifacts -If ($script:IsCIBuild) {
159176task UploadTestLogs - If ($script :IsCIBuild ) {
160177 $testLogsZipPath = " $PSScriptRoot /TestLogs.zip"
161178
162- Add-Type - Assembly System.IO.Compression.FileSystem - ErrorAction Ignore
163179 [System.IO.Compression.ZipFile ]::CreateFromDirectory(
164180 " $PSScriptRoot /test/PowerShellEditorServices.Test.Host/bin/$Configuration /net451/logs" ,
165181 $testLogsZipPath )
0 commit comments