1

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!

2
  • What you can do is put that type of code in your code (C# here): if (DebuggerLaunch && !Debugger.IsAttached) { Debugger.Launch(); } and run PowerShell normally. This will cause a dialog box to appear asking your what debugger you want to use (something like this help.qlik.com/en-US/qlikview-developer/May2022/Subsystems/…) and then you will enter your code. Commented Oct 20, 2022 at 17:07
  • the parameter is debugexe so i guess it's expecting an executable not the project/sln file Commented Oct 21, 2022 at 15:55

1 Answer 1

1
+50

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"
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry for the delay in rating/approving answer. This is correct and works great! So it looks like there wasn't a 'debug' command like I had thought and more to activate the debug option using command then to point to what file would be running?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.