I see demos where a folder with an angular app is opened in visual studio code using
code . from the terminal.
Could I do the same with Visual Studio. Perhaps I should write Powershell Scripts to accomplish the same?
I was able to open a folder from command line using the following in VS 2017
devenv.exe /Edit <path to folder> Locate the .exe file of the IDE environment (should be found in the IDE folder in the directory on which VS 2017 was installed). On my system, the exact path for the .exe file is:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE Yours might differ, but you should be able to find it. If not, just use the windows search feature to look for devenv.exe.
Once you've located the directory on which devenv.exe resides, proceed to add the path of that directory to your PATH environment variable. There are 3 ways to do that. The easiest way is to use the Windows GUI-based environment editor. Or you could use a third party environment editor (I recommend RapidEE). Another way is to do it directly from the command prompt.
And that's basically it. You're good to go. So let's say you have a directory containing all your source codes and header files at C:\DevFiles. Now, you can just launch your command prompt and from there either cd to C:\DevFiles and then type devenv . OR you can straight away type devenv C:\DevFiles
I think this is currently not possible.
The first requirement is to be able to start Visual Studio from the command line.
The equivalent of the “code” command is “devenv”. If you type this in your command line Visual Studio opens. Just ensure that the command is included in your path if you use a normal command prompt. It is already included in the path variable if you use the Visual Studio Command prompt.
The dot in the code . sets the current directory as working directory. If you are running < VS 2017 you are already out of luck now. In older version of Visual Studio it is not possible to work with such a folder approach. However, in Visual Studio 2017, you can open code from nearly any type of directory-based project into Visual Studio without the need for a solution or project file.
This could all be so easy now if only it would possible to pass this information to the devenv command.
However this is not the case: https://learn.microsoft.com/en-us/visualstudio/ide/reference/devenv-command-line-switches
Thus you would have to find another way to make Visual Studio 2017 in effect do something like File > Open > Folder and set the current directory as working folder.
This might be possible if you write a Visual Studio extension and hook up on the connected event.
But in essence the answer to your question is “not possible at the moment.”
The OP has been answered already and my answer only expounds on what has been said. The BLUF is <pathToVS>devenv.exe /Edit <pathToFolder> or <path to VS>devenv.exe <path to folder>
I am forced to use VS2017, VS2019, and VS2022.
I added the path to my environment vars and had consistent success where using the full path in a literal would fail.
Since I work primarily from PowerShell I made this function for my needs. This uses the associated version of visual studio by invoking the solution [.sln] file. My .sln files are associated with the 'Microsoft Visual Studio Version Selector' If you only have one VS installed it still works as your sln files [should] be associated with your VS.
function Open-Solution { <# .SYNOPSIS Open solution file for visual studio .DESCRIPTION Open proper version of visual studio -RootDirectory folder to search for solution in or to open in VS <Usage> PS C:\>sln - Open folder or solution in the active directory PS C:\>sln .\myApp - Open folder or solution in the .\myApp directory passed in the parameter PS C:\>sln -path .\myApp - Open folder or solution in the .\myApp directory passed in the parameter #> [Alias('sln')] param ( [Alias('path')] [Alias('searchpath')] [string]$RootDirectory = $PWD ) $solutions = Get-ChildItem -Recurse -Path $RootDirectory -Filter "*.sln" if ($solutions.Count -eq 1) { Invoke-Item $solutions.FullName } elseif ($solutions.Count -eq 0) { $Yes = New-Object System.Management.Automation.Host.ChoiceDescription '&Yes, Open current folder', "Open [$RootDirectory] in VS"; $No = New-Object System.Management.Automation.Host.ChoiceDescription '&No', "Do Not Open [$RootDirectory]"; $options = [System.Management.Automation.Host.ChoiceDescription[]]($Yes, $No); $title = "No solution files found searching [$RootDirectory]`n`n"; $message = "Would you like to open $RootDirectory in Visual Studio?"; $result = $host.ui.PromptForChoice($title, $message, $options, 1); switch ($result) { 0 { Write-Host Opening [$RootDirectory] in VS -ForegroundColor green; Invoke-Command {devenv.exe $RootDirectory }; break; } 1 { break; } default { break; } } } elseif ($solutions.Count -gt 1) { #TODO: allow selection deal with subfolders. (Doubt juice worth squeeze) Write-Host "`nI found more than 1 solution. Which one do you want to open?" -ForegroundColor Yellow; $solutions | Format-Table @{ Label="Solutions"; Expression={" --> $_"} } } } I hope this adds value to your work stream.
Cheers
Replace with project folder's path, or . for current directory.
start devenv <path> I don't know if this could be helpful but this might be the way to open a folder in visual studio.
explorer .