How can I open a solution file from powershell?

Viewed 2038

I'm new to powershell and I'm looking to create a powershell script to open two different solution files with two different versions of visual studio. I have the commands for opening up the different visual studio versions, but not sure how to open the solutions with each one. Here is what I have so far.

$vs19 = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.exe" 
$vs19WorkDir = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\"
$vs15 = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe"
$vs15WorkDir = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\"

Start-Process $vs19 -WorkingDirectory $vs19WorkDir
Start-Process $vs15 -WorkingDirectory $vs15WorkDir

2 Answers

Although not super obvious at first glance, the devenv command line reference mentions:

  • When specifying a solution or project, the first argument is the name of the solution file or project file, including file path.

With this in mind, I tried the following against Visual Studio 16 (2019):

& "path\to\devenv.exe" "path\to\a\solution.sln"

and it opened the solution in question, so you should be able to do it with:

Start-Process $vs19 -WorkingDirectory $vs19WorkDir -ArgumentList "c:\path\to\solution.sln"

I wrote a Powershell script to solve this problem. It was inspired by @Mathias R. Jessen's answer. You can find it on this Github gist

EDIT: I shared the gist on Reddit as well and it turns out that there are much cooler and intuitive ways of achieving this on PowerShell. Check them out as well.

PS: `The fastest method I've seen so far is by typing *.sln, then hitting Tab and Enter

Related