How do you prevent Visual Studio 2012 from closing IE when you stop debugging? - 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).

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 to stop browser closing automatically when you stop debugging on VS 2017

I'm trying out the new VS 2017 RC and wondering if anyone knows how to get the previous debugging behavior back
In VS 2015 it went like this:
Press start debugging
Website opens in new Chrome tab
Press stop debugging
Website is still open and the site is still running/active
Now in 2017:
Press start debugging
Website opens in new window that can't dock with any other Chrome windows/tabs
Press stop debugging
Website/Chrome window closes, can't continue using the site unless I manually go to the localhost window in Chrome
Is it possible in 2017 to switch back to the 2015 style? So the Chrome/Website window can dock with other Chrome windows/tabs, and it stays open after you stop debugging?
Additionally, I find the new Chrome window frustrating to use, as it seems not to have any history/content available. E.g I can't autocomplete forms or urls, which is very annoying when I'm trying to test a form
Visual Studio 2017 version 15.7 and higher & Visual Studio 2019 changed things again.
Disabling the following checkboxes will allow you to keep the browser open (doesn't close after stop debugging) and opens another tab (instead of another window):
Tools > Options > Debugging > General
Disable "Enable JavaScript debugging for ASP.NET (Chrome, Edge and IE)".
Tools > Options > Projects and Solutions > Web Projects
(Visual Studio 2017) Disable "Stop debugger when browser window is closed".
(Visual Studio 2019) Disable "Stop debugger when browser window is closed, close browser when debugging stops".
The reason for the change in behavior is due to VS 2017's support for debugging JavaScript/TypeScript running in Chrome. See announcement here https://blogs.msdn.microsoft.com/webdev/2016/11/21/client-side-debugging-of-asp-net-projects-in-google-chrome/
To return to the 2015 behavior where Chrome is not closed by the debugger, disable the IE/Chrome script debugger in Tools -> Options like so:
For those of you who updated to Visual Studio 2019, that config is now under
Tools > Options...
And then in the options dialog (see image below)
Projects and Solutions > Web Project :
Uncheck Stop debugger when broswer window is closed, close browser when debugging
I am writing this answer as I think the previous ones cover only half of the problem.
First thing you want is to get rid of this annoying 'run chrome as a new window and auto-close when stopped debugging'
Tools → Options → uncheck Enable JavaScript debugging for ASP.NET
After doing that when starting debugging chrome opens a new tab, after stopping the tab is not closed but refreshing website shows white screen
again in the Tools → Options
uncheck Enable Edit and Continue
Since now you have your old behaviour back.
If your project is .net core:
in Properties folder > launchSettings.json file set this config :
"launchBrowser": false,
Else in visual studio 2022 :
Tools > Options > Projects and Solutions > Web Projects
uncheck : Stop debugger when browser window is closed, close browser when debugging stops
Go to Tools -> Options and search for "Stop Debugger". Then select the node Web Projects under Projects and Solutions. Uncheck "Stop debugger when browser window is closed". Before this option your should apply #jerone's suggestion.
PS: This option can be used after VS version 15.7
There are two ways to do this:
Either Launch without debugging by pressing ctrl + f5 or
Launch with debugging (pressing f5) and then go to the Debug menu and press "Detach All"
Hope that helps.

Stop visual studio opening layout page everytime I refresh mvc web app

I'm using Visual Studio 2015.
If you create a new MVC project with all the basics it gives you (home controller, account controller, etc..), then press F5 to start it, visual studio shows the "_layout.cshtml" page in a preview window.
This gets rather frustrating if you're trying to make "on-the-fly" changes to a specific view, press F5 to refresh and see your changes, then alt-tab back to visual studio, only for it to have auto-previewed the layout page again.
How do you turn this feature off?
In Visual Studio, you should disable the checkbox for 'Enable browser link'.
I was able to reproduce on a new install. For me, the offender was "Web Essentials" extension. Try to disable and restart VS.
Also, it only happens with Edge's developer tools open. Haven't seen this with Firefox nor Chrome.
This is caused by the F12 Developer Tools where the page of the selected element in the DOM Explorer/Elements tab is automatically opened and synchronized in Visual Studio.
If you want to keep the Browser Link feature enabled, the F12 Developer Tools window open, and not lose your currently focused tab in Visual Studio, here's a work-around:
1. Right-click on the _Layout.cshtml tab in Visual Studio and select New Vertical Tab Group.
If you already have a tab group open, select Move to Next Tab Group.
2. Resize the splitter control of the tab group so that the tab group is barely visible.
3. Repeat these steps for all other files that automatically open in Visual Studio which disrupt your workflow.
I am unable to replicate your exact problem, but the following should disable the preview tab:
Type "preview" into Quick Launch
Select "Environment --> Tabs and Windows"
Disable "Allow new files to be opened in the preview tab"

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

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