Quickly Open Visual Studio on the Command Line

Published on Tuesday, October 6th, 2020

I'm a huge fan of using the command line for things, and I use the command line to open vs code all the time with code ..

I wanted a way to do the same thing for visual studio, turns out you can! In the example below I use visual studio in a directory. The code works by searching recursivel for the .sln file and passing the solution file path to devenv.exe and you're set.

Just stick this in your powershell profile, which can be opened with vs code with code $PROFILE at the powershell prompt. Now type vs . in the root of your favorite visual studio project.

function vs([string]$start = ".") {
# Locate a solution file recursivle "*.sln"
$sln = ((Get-ChildItem -Path $start -Filter *.sln -Recurse) | where { $_.fullname -notmatch 'node_modules' })[0]

# Open the solution file with the well know visual studio path
# If you have the community edition replace "Professional" with "Community"
& "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.exe" $sln.fullname
}

This approach can be used for more than just visual studio, it could be applied to any program that has it's own project type. Possibilities might be unity, photoshop, aseprite, etc.

Hope this makes your visual studio development a delight! -Erik

Help support me on Github Sponsors or Patreon

Become a Patron!