hannes neukermans
hannes neukermans

Reputation: 13277

Visual studio: How to open a specific solution directly from command line?

I want to open a specific solution (.sln) in visual studio directly from the command line.

Using the command, I tried

devenv "full-path-to-sln-file.sln"

but it didn't work.

How do I do this?

Upvotes: 2

Views: 2198

Answers (6)

jimmytricks
jimmytricks

Reputation: 51

You can open a solution file with Visual Studio directly if you are within a folder that contains the solution file, looking for it recursively (Powershell 7.0) by doing the following:

Open powershell, type

echo $profile

Open up the location of your profile, save the below into it:

function vs
{
Get-ChildItem *.sln -Recurse | Invoke-Item
}

Then just type vs into a folder and it will go through the sub directories looking for the solution file and open one if found

Upvotes: 1

Andy
Andy

Reputation: 1228

for macOs I just use:

open projectname.csproj

it will open it in visual studio 2019 for me

Upvotes: 0

hannes neukermans
hannes neukermans

Reputation: 13277

You can just use explorer.exe !! In your command line type in:

explorer mysolution.sln

Upvotes: 8

Nick Spreitzer
Nick Spreitzer

Reputation: 10598

Try WhatsNew. From the readme:

Why fish around for Visual Studio solution files using Windows Explorer when you can find and launch them from your terminal window with just three little letters? Run sln (an alias for Open-Solution) to recursively search your current working directory for a solution file and launch it, if one is found.

Upvotes: 0

Dave Mateer
Dave Mateer

Reputation: 6626

I wrote an open source application called OpenVSSolution to do exactly this.

Essentially:

  • Put this helper exe somewhere in your PATH
  • The exe scans the current directory for a .sln file
  • The exe opens devenv passing in the sln file

The explanation is on here: https://davemateer.com/coding/2018/11/14/Open-visual-studio-from-command-line.html

I find this incredibly useful and is how I open all solutions.

Upvotes: 1

EzLo
EzLo

Reputation: 14189

Use the full path to the devenv.exe executable and the full path to the sln solution file, both wrapped in quotes and with a space in between. If your solution file is in a network path, make sure that it does not require authentication before accessing the destination folder.

C:\Users\YourWindowsUser>"D:\Visual Studio\Common7\IDE\devenv.exe" "\\networkDirectory\profiles\Desktop\VisualStudioSolutions\Project999.sln"

Upvotes: 2

Related Questions