diff --git a/build.psm1 b/build.psm1 index 39e56d5d73..7c4b9ead2e 100644 --- a/build.psm1 +++ b/build.psm1 @@ -68,14 +68,8 @@ function Start-PSBuild { $FullCLR = $true } - if (-not $NoPath) { - Write-Verbose "Appending probable .NET CLI tool path" - if ($IsWindows) { - $env:Path += ";$env:LocalAppData\Microsoft\dotnet" - } else { - $env:PATH += ":$env:HOME/.dotnet" - } - } + # Add .NET CLI tools to PATH + Find-Dotnet if ($IsWindows) { # use custom package store - this value is also defined in nuget.config under config/repositoryPath @@ -241,6 +235,9 @@ function New-PSOptions { [switch]$FullCLR ) + # Add .NET CLI tools to PATH + Find-Dotnet + if ($FullCLR) { $Top = "$PSScriptRoot/src/Microsoft.PowerShell.ConsoleHost" } else { @@ -344,6 +341,7 @@ function Start-PSPester { function Start-PSxUnit { [CmdletBinding()]param() + if ($IsWindows) { throw "xUnit tests are only currently supported on Linux / OS X" } @@ -353,6 +351,9 @@ function Start-PSxUnit { return } + # Add .NET CLI tools to PATH + Find-Dotnet + $Arguments = "--configuration", "Linux", "-parallel", "none" if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) { $Arguments += "-verbose" @@ -588,6 +589,9 @@ function Publish-NuGetFeed [string]$VersionSuffix ) + # Add .NET CLI tools to PATH + Find-Dotnet + @( 'Microsoft.PowerShell.Commands.Management', 'Microsoft.PowerShell.Commands.Utility', @@ -885,6 +889,9 @@ function Start-TypeGen throw "Start-TypeGen is not supported on non-windows. Use src/TypeCatalogGen/build.sh instead" } + # Add .NET CLI tools to PATH + Find-Dotnet + Push-Location "$PSScriptRoot/src/TypeCatalogParser" try { @@ -933,6 +940,24 @@ function Start-ResGen } +function Find-Dotnet() { + $originalPath = $env:PATH + $dotnetPath = if ($IsWindows) { + "$env:LocalAppData\Microsoft\dotnet" + } else { + "$env:HOME/.dotnet" + } + + if (-not (precheck 'dotnet' "Could not find 'dotnet', appending $dotnetPath to PATH.")) { + $env:PATH += [IO.Path]::PathSeparator + $dotnetPath + } + + if (-not (precheck 'dotnet' "Still could not find 'dotnet', restoring PATH.")) { + $env:PATH = $originalPath + } +} + + function script:log([string]$message) { Write-Host -Foreground Green $message }