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
+ task SetupDotNet - Before Clean , Build, BuildHost, Test, TestPowerShellApi {
9
+
10
+ # Bail out early if we've already found the exe path
11
+ if ($script :dotnetExe -ne $null ) { return }
12
+
13
+ $requiredDotnetVersion = " 1.0.0-preview4-004233"
14
+ $needsInstall = $true
15
+ $dotnetPath = " $PSScriptRoot /.dotnet"
16
+ $dotnetExePath = " $dotnetPath /dotnet.exe"
17
+
18
+ if (Test-Path $dotnetExePath ) {
19
+ $script :dotnetExe = $dotnetExePath
12
20
}
21
+ else {
22
+ $installedDotnet = Get-Command dotnet - ErrorAction Ignore
23
+ if ($installedDotnet ) {
24
+ $dotnetExePath = $installedDotnet.Source
13
25
14
- exec {
15
- if (! ((& dotnet -- version) -like " *preview4*" )) {
16
- Write-Error " You must have at least preview4 of the dotnet tools installed."
26
+ exec {
27
+ if ((& $dotnetExePath -- version) -eq $requiredDotnetVersion ) {
28
+ $script :dotnetExe = $dotnetExePath
29
+ }
30
+ }
31
+ }
32
+
33
+ if ($script :dotnetExe -eq $null ) {
34
+
35
+ Write-Host " `n ### Installing .NET CLI $requiredDotnetVersion ...`n " - ForegroundColor Green
36
+
37
+ # Download the official installation script and run it
38
+ $installScriptPath = " $ ( $env: TEMP ) \dotnet-install.ps1"
39
+ Invoke-WebRequest " https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview4/scripts/obtain/dotnet-install.ps1" - OutFile $installScriptPath
40
+ $env: DOTNET_INSTALL_DIR = " $PSScriptRoot \.dotnet"
41
+ & $installScriptPath - Version $requiredDotnetVersion - InstallDir " $env: DOTNET_INSTALL_DIR "
42
+
43
+ Write-Host " `n ### Installation complete." - ForegroundColor Green
44
+ $script :dotnetExe = $dotnetExePath
17
45
}
18
46
}
47
+
48
+ # This variable is used internally by 'dotnet' to know where it's installed
49
+ $script :dotnetExe = Resolve-Path $script :dotnetExe
50
+ if (! $env: DOTNET_INSTALL_DIR )
51
+ {
52
+ $dotnetExeDir = [System.IO.Path ]::GetDirectoryName($script :dotnetExe )
53
+ $env: PATH = $dotnetExeDir + [System.IO.Path ]::PathSeparator + $env: PATH
54
+ $env: DOTNET_INSTALL_DIR = $dotnetExeDir
55
+ }
56
+
57
+ Write-Host " `n ### Using dotnet at path $script :dotnetExe `n " - ForegroundColor Green
19
58
}
20
59
21
60
task Clean {
@@ -36,7 +75,7 @@ task TestPowerShellApi {
36
75
BuildForPowerShellVersion v5r2
37
76
}
38
77
39
- task BuildHost EnsureDotNet , {
78
+ task BuildHost {
40
79
# This task is meant to be used in a quick dev cycle so no 'restore' is done first
41
80
exec { & dotnet build - c $Configuration .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj }
42
81
}
0 commit comments