Shortcut button for remote debugging in Visual Studio - visual-studio

I want to add a shortcut-button in Visual Studio 2015. Clicking this button should just emulate "Attach To Process" -> Select "w3wp.exe" -> Attach.
Does anyone know how to do it?

You can't do those two commands on one toolbar button click apart from creating or using an existing Visual Studio extension.
Creating a Visual Studio extension would be feasible but somewhat involved (as a complete project in itself).
Available Extensions:
The first extension you could use is Visual Commander (detailed below) to create a Macro.
Depending on your needs you could also use AttachTo which provide a one click option to attach to IIS.
Finally there is also Debug Attach Manager which can attach to specific process and then remember it.
Using a macro to achieve the desired effect:
As mentioned by #Sergey Vlasov, you can can install a Visual Studio Extension named Visual Commander that brings back Macros in Visual Studio. Then you can program a macro to do this for you. The code for the macro comes from another SO answer
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
Adding the shortcut button:
You can also easily add a button in your toolbar to add "Attach to Process..." if you prefer to have the button on your toolbar.
To do this go in the Menu under TOOLS. Then choose Customize.
There select the second tab "Commands".
The select Toolbar and choose the toolbar you want the button to appear in. For example "Debug" if you want it to appear during debugging.
Then press the Add Command... button and choose the Debug category. There you will find the Attach to Process.
This would make it more readily available if you prefer to use the toolbar.

Related

How to select debug profile in Visual Studio?

I have a .NET Core 3 (not ASP) project in Visual Studio 2019 that has two different launch profiles:
But whenever I launch my project, it always uses the first profile, even if I have the second profile selected in my project settings. How do I tell Visual Studio to actually use the other launch profile?
EDIT: This is what my toolbar looks like:
I have no dropdown to select a launch configuration. I found the "Start Debug Target" command and can add that to my toolbar, but it doesn't have a dropdown either, it looks just like the regular start button.
In projects you can configure the profile, not select it.
In order to select a profile you should choose it from dropdown list next to start button:
EDIT
On my VS the button is called Debug Target and is placed under Standard section in toolbar.
However, there's something fishy about this button in visual studio. When I removed button from visual studio I couldn't find it among other commands to readd it. After some googling I even found out there were problems with this in past.
https://developercommunity.visualstudio.com/content/problem/323626/if-you-remove-debug-target-from-toolbar-you-can-ne.html
Ewentually I found out two ways to bring it back.
Reset the standard toolbar
Add it from Add or remove buttons section next to standard toolbar

Adding a Visual Studio toolbar button for a command that is only available as a keyboard shortcut

This question relates to this ReSharper YouTrack issue.
In Visual Studio 2010 with ReSharper 7.1.1 installed, if I go to Tools > Options > Environment > Keyboard, there is a command called ReSharper_SilentCleanupCode.
I would like to bind this command to a toolbar button.
This seems to be impossible using Tools > Customize > Commands because the only commands available within this dialog are for actions that already have an associated menu item. The particular ReSharper command I'm interested in (Silent Code Cleanup) doesn't appear in any menu, so it cannot be assigned to a toolbar button using the "GUI".
Is there any other way to bind a keyboard-only command to a toolbar button? (One of ReSharper's programmers thought the "VS script editor" could be used, but I'm not having any luck finding info on this.)
Edit
I should have mentioned this in the first place. While azhrei's macro solution is great for Visual Studio 2010, it will break once I upgrade to VS 2012, because macros are no longer supported. If someone has a solution that will continue to work in VS 2012, that would be preferable. (Or perhaps VS 2012 toolbars don't have the same limitation in the first place?)
Add a macro that executes the command, then add the macro to a toolbar.
This works because it makes the keyboard-only command appear in the Macros menu in the Customize Commands dialog.
Details
Add a macro which does this:
Sub _ReSharper_SilentCleanupCode()
DTE.ExecuteCommand("ReSharper_SilentCleanupCode")
End Sub
Put this macro in a module which appears in Customize..Commands..AddCommand..Categories..Macros, such as Samples or MyMacros.RecordingModule, but not MyMacros.Module1 (the default when using the macro IDE).
Go to Tools..Customize..Command and select the Toolbar you want.
Now Add Command... and select the Macros category.
Select your Macros.Samples._ReSharper_SilentCleanupCode macro.
Click Modify Selection and change the name to #-) or whatever text makes you think ReSharper Silent Code Cleanup without being too long for your toolbar. :-)
I tried this with Visual Studio 2010 and ReSharper 7.1.2.
Edit
Visual Commander is a apparently way to get this going on VS2012 as well - see comments below for more.

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 :-)

Invoke an exe from Visual Studio's toolbar

How do you customize a button in a Visual Studio toolbar to run a certain executable?
I use VS2010, so a specific answer would be even better, although this might be the same cross versions...
Under Tools, External Tools add your executable.
To make it appear in the toolbar then click on the small triangle at the end of the toolbar and select Add or Remove Button, then Customize. Click Add Command and from category Tools select External command 1 (or another if you have multiple).

How to add Close All But Pinned command to Visual Studio 2010 menu or toolbar?

I've implemented the suggestions in Scott Hanselman's blog post Simplify your Visual Studio 2010 Toolbar and Free Your Mind. Very cool.
Where can I find/execute the command "Close All But Pinned" that is part of Visual Studio Productivity Power Tools.
You can assign a shortcut in Tools -> Options -> Environment -> Keyboard. Search for Window.CloseAllButPinned in the Show commands containing: textbox and assign your own key combination.
Similarly, you can execute that command in the "Go To Find Combo" small box, i.e. press Ctrl+/ then type ">Window.CloseAllButPinned", press Enter.
It is a two step process:
Create a Macro with the following
Public Module myToolbar
Sub CloseAllButPinned()
DTE.ExecuteCommand("Window.CloseAllButPinned")
End Sub
End Module
Right click on your Toolbar, choose Customize, Add Command, Category Macro, choose MyMacros.myToolbar,CloseAllButPinned
Then click ModifySelection and give it an easy to remember name

Resources