Add Find-Dotnet to make build module smarter

New function smartly adds the probable location of the .NET CLI tools to
the path if `dotnet` is not found. If it is still not found, it restores
the path. All functions using `dotnet` should call `Find-Dotnet` first.
This commit is contained in:
Andrew Schwartzmeyer 2016-06-20 11:59:14 -07:00
parent 42d1d05d85
commit 511936606e

View file

@ -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
}