Skip to content

trollixx/vsenv

Repository files navigation

vsenv

CI Release License

Visual Studio environment activator that works in cmd, PowerShell, nushell, bash, and fish.

vcvars*.bat and Enter-VsDevShell only work in cmd and PowerShell. vsenv provides the same environment to any shell by capturing it once and reading from cache thereafter.

Install

Download a release (recommended)

Grab vsenv-amd64.exe (or vsenv-arm64.exe on ARM) from the latest release and drop it somewhere on your PATH.

Or with the gh CLI:

gh release download --repo trollixx/vsenv --pattern vsenv-amd64.exe --output ~/bin/vsenv.exe

Via go install

go install github.com/trollixx/vsenv@latest

Builds from source, lands in $GOPATH/bin. Reports 0.1.0-dev as the version since release-time ldflags aren't applied to local builds.

From source

git clone https://github.com/trollixx/vsenv
cd vsenv
go build -o vsenv.exe

Single static binary, no CGO.

Usage

vsenv list                                       # show discovered VS installs
vsenv refresh                                    # rebuild caches
vsenv exec [--arch x64] -- <cmd> [args...]       # run one command in VS env
vsenv shell [--arch x64] [--shell nu]            # interactive child shell
vsenv env --shell powershell|cmd|nu|bash|fish    # print env for profile

exec and shell set the env in a child process; the parent shell stays clean. env prints shell-flavored commands you can source from your profile.

Profile integration

PowerShell ($PROFILE):

vsenv env --shell powershell | Out-String | Invoke-Expression

Nushell (config.nu):

load-env (vsenv env --shell nu | from json)

Bash (.bashrc):

eval "$(vsenv env --shell bash)"

Fish (config.fish):

vsenv env --shell fish | source

How it works

vsenv runs vswhere.exe to find Visual Studio installations and caches the result. For each (install, arch, host-arch, args) tuple it invokes VsDevCmd.bat once, captures the env diff, and writes it to %LOCALAPPDATA%\vsenv\. Subsequent invocations read the cache (~20 ms). The cache invalidates when the VS install version changes; vsenv refresh forces a rebuild.

VsDevCmd.bat is the same script Microsoft's Enter-VsDevShell cmdlet wraps internally — vsenv is that, minus the PowerShell-only constraint and the telemetry.

Requirements

  • Windows
  • Visual Studio 2017+ or VS Build Tools (anything vswhere.exe can find)

About

Cross-shell Visual Studio environment activator: cmd, powershell, nushell, bash, fish

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages