5
5
6
6
# Requires -Modules @ {ModuleName = " InvokeBuild" ;ModuleVersion = " 3.2.1" }
7
7
8
- task EnsureDotNet - Before Clean , Build, BuildHost, Test, TestPowerShellApi {
9
- # TODO: Download if it doesn't exist in known paths
10
- if (! (Test-Path ' c:\Program Files\dotnet\dotnet.exe' )) {
11
- Write-Error " dotnet is not installed"
8
+ if ($env: APPVEYOR -ne $null ) {
9
+ dotnet -- info
10
+ }
11
+
12
+ task SetupDotNet - Before Restore, Clean , Build, BuildHost, Test, TestPowerShellApi {
13
+
14
+ # Bail out early if we've already found the exe path
15
+ if ($script :dotnetExe -ne $null ) { return }
16
+
17
+ $requiredDotnetVersion = " 1.0.0-preview4-004233"
18
+ $needsInstall = $true
19
+ $dotnetPath = " $PSScriptRoot /.dotnet"
20
+ $dotnetExePath = " $dotnetPath /dotnet.exe"
21
+
22
+ if (Test-Path $dotnetExePath ) {
23
+ $script :dotnetExe = $dotnetExePath
12
24
}
25
+ else {
26
+ $installedDotnet = Get-Command dotnet - ErrorAction Ignore
27
+ if ($installedDotnet ) {
28
+ $dotnetExePath = $installedDotnet.Source
29
+
30
+ exec {
31
+ if ((& $dotnetExePath -- version) -eq $requiredDotnetVersion ) {
32
+ $script :dotnetExe = $dotnetExePath
33
+ }
34
+ }
35
+ }
36
+
37
+ if ($script :dotnetExe -eq $null ) {
13
38
14
- exec {
15
- if (! ((& dotnet -- version) -like " *preview4*" )) {
16
- Write-Error " You must have at least preview4 of the dotnet tools installed."
39
+ Write-Host " `n ### Installing .NET CLI $requiredDotnetVersion ...`n " - ForegroundColor Green
40
+
41
+ # Download the official installation script and run it
42
+ $installScriptPath = " $ ( $env: TEMP ) \dotnet-install.ps1"
43
+ Invoke-WebRequest " https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview4/scripts/obtain/dotnet-install.ps1" - OutFile $installScriptPath
44
+ $env: DOTNET_INSTALL_DIR = " $PSScriptRoot \.dotnet"
45
+ & $installScriptPath - Version $requiredDotnetVersion - InstallDir " $env: DOTNET_INSTALL_DIR "
46
+
47
+ Write-Host " `n ### Installation complete." - ForegroundColor Green
48
+ $script :dotnetExe = $dotnetExePath
17
49
}
18
50
}
51
+
52
+ # This variable is used internally by 'dotnet' to know where it's installed
53
+ $script :dotnetExe = Resolve-Path $script :dotnetExe
54
+ if (! $env: DOTNET_INSTALL_DIR )
55
+ {
56
+ $dotnetExeDir = [System.IO.Path ]::GetDirectoryName($script :dotnetExe )
57
+ $env: PATH = $dotnetExeDir + [System.IO.Path ]::PathSeparator + $env: PATH
58
+ $env: DOTNET_INSTALL_DIR = $dotnetExeDir
59
+ }
60
+
61
+ Write-Host " `n ### Using dotnet at path $script :dotnetExe `n " - ForegroundColor Green
62
+ }
63
+
64
+ task Restore {
65
+ exec { & dotnet restore }
19
66
}
20
67
21
68
task Clean {
22
- exec { & dotnet clean .\PowerShellEditorServices.sln }
69
+ exec { & dotnet clean }
23
70
}
24
71
25
72
function BuildForPowerShellVersion ($version ) {
73
+ # Restore packages for the specified version
26
74
exec { & dotnet restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -- / p:PowerShellVersion= $version }
27
75
28
76
Write-Host - ForegroundColor Green " `n ### Testing API usage for PowerShell $version ...`n "
29
- exec { & dotnet build -f net451 .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -- / p:PowerShellVersion= $version }
77
+ exec { & dotnet build -f net451 .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -- / p:PowerShellVersion= $version }
30
78
}
31
79
32
80
task TestPowerShellApi {
33
81
BuildForPowerShellVersion v3
34
82
BuildForPowerShellVersion v4
35
83
BuildForPowerShellVersion v5r1
36
- BuildForPowerShellVersion v5r2
84
+
85
+ # Do a final restore to put everything back to normal
86
+ exec { & dotnet restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj }
37
87
}
38
88
39
- task BuildHost EnsureDotNet , {
89
+ task BuildHost {
40
90
# This task is meant to be used in a quick dev cycle so no 'restore' is done first
41
91
exec { & dotnet build - c $Configuration .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj }
42
92
}
43
93
44
94
task Build {
45
- exec { & dotnet restore - v:m .\PowerShellEditorServices.sln }
46
95
exec { & dotnet build - c $Configuration .\PowerShellEditorServices.sln }
47
96
}
48
97
@@ -67,4 +116,5 @@ task LayoutModule -After Build, BuildHost {
67
116
Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices.Host\bin\$Configuration \netstandard1.6 \* - Filter Microsoft.PowerShell.EditorServices* .dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Core\
68
117
}
69
118
70
- task . Clean , Build, Test, TestPowerShellApi
119
+ # The default task is to run the entire CI build
120
+ task . Restore, Clean , Build, TestPowerShellApi, Test
0 commit comments