What do I do to run Windbg/dbeng.dll commands from within the Visual Studio debugger and the Immediate Window? - visual-studio

I saw in a video talk by Bart de Smet where he was running Windbg commands by typing them into the Immediate Window in Visual Studio when running the project in debug mode inside the Visual Studio debugger.
So, I wanted to try that myself. So here's what I did:
I went to the Project Properties dialog and then selected the Debug tab, then checked the Enable native code debugging in the Enable Debuggers section.
I set a breakpoint on one of the lines and then launched the project with debugging by hitting F5. When the breakpoint was hit, I opened the Immediate Window and typed the .load command to load sos.dll.
But the message I got as a result read:
.load "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\sos.dll"
error CS1525: Invalid expression term '.'
Is there something else I need to do?
I am using Visual Studio 2015 Community edition.

Run your application without debugging
Choose Debug/attach to process ...
Choose "Windows User Mode Debugger" as transport
Click "Refresh"
Choose your application
Click "Attach"
Open the "Immediate Window", which will labelled be "Debugger Immediate Window"
Enter WinDbg commands

Related

Make Visual Studio 2019 Always Run as Administrator from Start Bar Recent Solutions List

I recently upgraded to Windows 10 and Visual Studio 2019.
Prior to the upgrade, Visual Studio 2017 would always run as Administrator. I did not think much of this, but now that it is gone it is causing me problems.
The primary one is that it will not load my projects that use my local instance of IIS.
I usually launch Visual Studio from my start bar. Right now this goes like this:
Right click on the icon on the start bar and select my solution.
It loads and then I realize that the main project did not load.
Close visual studio, open as admin
Pick my solution and then it loads.
I would really like to only have to do #1 above. Is there someway I can edit the shortcut on the start bar to have it always launch as Administrator?
Turns out that Visual Studio uses different permissions when you click on the list of shortcut options it offers in the start menu. (IE to load a recent solution directly.)
Selecting the Properties->Advanced->"Run as Administrator" did not cause these to run as administrator.
But this did it:
Find devenv.exe (Visual Studio's executable)
Right Click on it and select "Troubleshoot Compatibility".
On the Program Compatibility Troubleshooter window, click on Troubleshoot Program
Check that the program requires additional permissions and click Next
On the next window, click on Test the program… and VS will open as administrator
Click next and then click on Yes, save these settings for this program
Now Visual Studio will ALWAYS run as administrator.
(Taken from: https://ppolyzos.com/2017/08/08/always-run-visual-studio-as-administrator/)

How do you prevent Visual Studio 2012 from closing IE when you stop debugging?

When I was using Visual Studio 2010, I could just "Detach All" and the web site would continue to run and the browser wouldn't close. That would enable me to attach a different solution to debug a separately compiled library. Now all that's left is "Stop Debugging" and "Terminate All".
Although the website is still running in the background, I have to open a new browser window and navigate back where I was.
Is there some way to go back to the 2010 functionality?
Detach All is still available in VS 2012. If you don't have it under Debug in Main Menu then you may need to add it manually (right click on toolbar, select Customize.. from context menu).

Visual Studio - Attach to process shortcut

When I want to debug I have to do Debug->Attach to Process -> Look for a process in the list -> Attach.
I was wondering if I can create some kind of a shortcut to do this for me?
The shortcut is Ctrl+Alt+P in Visual Studio 2005 and above.
The easiest way to do this is to write a macro which finds the DTE.LocalProcess you wan to target and automatically attach. For example
Public Sub AttachShortcut()
For Each proc In DTE.Debugger.LocalProcesses
If proc.Name = "what you're looking for" Then
proc.Attach()
Exit Sub
End IF
Next
End Sub
Note: This Stack Overflow Question is related and has a sample you may find useful
Attaching to a child process automatically in Visual Studio during Debugging
To enable the 'Attach to Process' toolbar button in Visual Studio 2013, 2015, 2017, 2019, and 2022
Right-click on any toolbar and click 'customize...'
Click the 'commands' tab
Click the 'Toolbar' radio button
Select the toolbar where you want your button to appear from the dropdown
Click the 'Add Command...' button
Select 'Debug' from the categories list on the left
Select 'Attach to Process' from the commands list on the right, and click ok. The button will appear on your selected toolbar.
Optionally, use the 'Move Up' and 'Move Down' buttons on the right to move your new button to your desired location within the toolbar. I keep mine just after the Debug button.
You can use the Alt key shortcut ALT+D,P to launch the "Attach to Process" window via Debug menu.
Once there, you can use your keyboard to search the list of Available Processes (e.g. type "w3wp" if you want to attach to an IIS app pool)
Writing a macro is one option, however it cannot deduct which process to attach to by itself.
Another nice solution is to map the "Attach to process" command to a shortcut key:
(Tools -> Options -> Environment -> Keyboard, type attach, like i did in this example, and select a shortcut key):
This answer should work for Visual Studio 2010.
I like having buttons to do this on my debug toolbar
https://gist.github.com/1406827
The gist contains a method for attaching to IIS (w3wp.exe) or ASP (aspnet_wp.exe) and also nunit (nunit-agent.exe). Instructions are included on how to add the macros to your debug toolbar.
For Visual Studio 2017, 2019, there is a ReAttach extension available. Very handy.
I use this built in "Shortcut"
ALT+D, P, W, ENTER
this opens the debug menu, selects attach to process, scrolls down to w3wp.exe and attaches.
It's long but should work in multiple visual studio versions with no setup required, with or without resharper and it works when running multiple IIS processes as you can choose which process to attach to.
Addins are probably a better way to do this now. I use one called "Attach to anything". You can find them in Visual Studio 2012. Go to "Tools" -> "Extensions and updates", search for "attach", and install "attach to anything".
Also see:
Automate "Attach to Process" in Visual Studio 2012
Alt+Shift+P to reattach the last attached process.
It works for me in Visual Studio 2017.
Personally I prefer to use Debugger.Launch() as suggested here
in this thread, because it doesn't need for references to the DTE (that's IDE-specific and must be explicitly referenced into the project to be used)
VS extensions
Debug Attach Manager
ReAttach
Resurrect
More: Search the VS Marketplace for "attach"
Keyboard
The attach to process shortcut is Ctrl+Alt+P in Visual Studio 2005 and above. You can then press the first letter of the process name you want, e.g. w for w3wp.exe and it'll jump to that, then Enter to attach.
You can use the Alt key shortcut ALT+D,P to launch the "Attach to Process" window via Debug menu.
Code
Add System.Diagnostics.Debugger.Launch() to your code
Current release is VS2015 at time of writing.
Go ahead and edit/extend this answer :-)

Launching "Visual Studio Just-In-Time Debugger" without prompting

I have set up my system to automatically attach the visual studio debugger when a certain application is launched using these instructions:
http://msdn.microsoft.com/en-us/library/a329t4ed%28printer%29.aspx
The problem is that I get a dialog box each time that requires me to confirm that I do indeed want to attach the debugger. The dialog also prompts me to specify which visual studio debugger I want to attach (I have VS2003, VS2005 and VS2008 installed on the system). I've selected "New instance of Visual Studio 2008" and checked the "Set the currently selected debugger as default."-box but the dialog keeps popping up.
Thanks
Andreas Brinck
There is a registry entry that determines how the debugger is started. Under
HKLM\Software\Microsoft\Windows NT\CurrentVersion\AeDebug
create a DWORD value named "Auto" with a value of 1, so no confirmation window displays

Visual Studio 2005 context menu launches server explorer: why?

For some reason, a variety of actions in Visual Studio 2005, actions that have nothing to do with SQL Server, are opening the "Connect to SQL Server" dialog. And it takes four (4) clicks on the CANCEL button to kill the dialog.
For example, if I right click on a class method in the Editor, hoping to find the Go To Definition option, the dialog opens.
Or if I run a project in Debug mode, and then close the app, the dialog opens.
I have to close VS and re-open it to get this to stop. But after a while, this behavior returns. What is causing it has eluded me.
Is this Microsoft's way to get me to upgrade to VS2008? OK, he's had VS2005 for too long. Time for him to upgrade. Invoke DriveCustomerMad.
Next time you see the dialog box, open a second copy of VS2005, attach its debugger to the first one, pause the process, and look at the call stack.
Do you have any addons installed?

Resources