Home > Mobile >  Use PowerShell to open Visual Studio and start debugging
Use PowerShell to open Visual Studio and start debugging

Time:10-26

Hello I have some light experience in PowerShell and I currently am using Visual Studio Community 2022. I want to run a PS script that will open a project I have in Visual Studio and run the debugger. I found an existing solution online but I may need help navigating and understanding what I may be doing wrong or if there is a different solution needed today. (The post I referenced was from 2015)

Start debugging a Visual Studio Project using Powershell script

In the above question the following code snippet is given to start VS and run the debugger.

param
(
    [Parameter(Mandatory = $false)]
    [String]
    $TargetFileName
)

& "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe" /command "Debug.Start" /debugexe "$TargetFileName"

Because in the initial code there is no specific route to the file I replaced $TargetFileName with the location/name of the file I'm using to test. My code is

param
(
    [Parameter(Mandatory = $false)]
    [String]
    $TargetFileName
)

& "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe" /command "Debug.Start" /debugexe "C:\Users\*MyUserName*\source\repos\testing\testproj.sln"

This is starting up VS fine but the test project itself isn't loading. Also while VS is loading I'll see a message that says "Command 'Debug.Start' is not available"

I'm thinking that's because there is an issue with the full file location string or Debug.Start could have been replaced by another command.

Any help is greatly appreciated. Thank you!

CodePudding user response:

I have tried this in my test environment for a different solution/project I had.

Below command works for me:

devenv /Run MyTestSolution\MyTestSolution.sln /command Debug.Start

For your code you can use:

param
(
    [Parameter(Mandatory = $false)]
    [String]
    $TargetFileName
)

& "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe" /Command "Debug.Start" /Run "C:\Users\*MyUserName*\source\repos\testing\testproj.sln"
  • Related