DEV Community

Ben Collins
Ben Collins

Posted on • Edited on

3 1

Using bootstrapped paket

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)"
    }
}

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (1)

Collapse
 
aggieben profile image
Ben Collins

P.S. - now that .NET Core supports CLI tools, it's easier to just use paket as a CLI tool.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay