I use the Paket package manager in several of my projects by bootstrapping, and so I wind up with a .paket
directory at the root of my project folder which contains the paket.exe
I need to use. I find it cumbersome to invoke it with relative paths like ../../../.paket/paket.exe
, so I wrote a little bit of powershell to ensure the bootstrapped paket is in my path.
This is in the Cmder $PrePrompt
function, but if you're not using Cmder, you can do this in the Prompt
function of your Powershell profile (which you would have to add if you don't have it already. See about_Prompts for more info.
The relevant bits of my user-profile.ps1
set up for Cmder:
Function Get-AncestorPath ($dir, $name) {
$target = Get-ChildItem $dir |? { $_.Name -eq $name }
if ($target -ne $Null) {
return $target
} elseif ($dir.Parent -ne $Null) {
return Get-AncestorPath $dir.Parent, $name
} else {
return $Null
}
}
[ScriptBlock]$PrePrompt = {
$paketDir = Get-AncestorPath $pwd ".paket" | Select-Object -ExpandProperty FullName
if ($paketDir -eq $Null) {
if ($Env:Path -like "*.paket*") {
Write-Verbose "Removing .paket path from `$Env:Path"
$Env:Path = $Env:Path -split ';' `
|? { $_ -notlike "*.paket*" } `
| Join-String -Separator ';'
}
return
}
Write-Verbose "Paket path: $paketDir"
if (($Env:Path -split ';') -notcontains $paketDir) {
Write-Verbose "Adding '$paketDir' to path..."
$Env:Path = "$paketDir;$($Env:Path)"
}
}
Top comments (1)
P.S. - now that .NET Core supports CLI tools, it's easier to just use paket as a CLI tool.