Archive for Visual Studio:
Visual Studio's Attach to process is an alternative to the good ol' F5 which builds your solution and lets you debug it. However Attach to process can be made a little bit easier using a few helpful tricks.
First of all, we need to add an external tool to Visual Studio:
- Go to Tools->External Tools and press Add to create a new tool.
- Fill in these values in the correct field:
Title: list w3wp
Arguments: list wp
Make sure "Use Output window" is checked and remember what order your tool has in the list, for instance 4th. Press Ok.
Remember that your w3wp processes will be in Visual Studio's output window when using this tool!
Now we want easy access to our tool. Let's give it a shortcut command:
- Go to Tools->Options->Environment->Keyboard.
- In the Show command containing box, search for tools.external
- Find the correct Tools.ExternalCommandX where X matches the order of your tool in the external tools list, for instance 4.
Assign shortcut keys to your command and press Ok. I use Alt+E.
Next up, we need to use the helpful Visual Studio extension ReAttach. Download and install it. It helps us reattach to the same w3wp process over and over again :-) I've written about ReAttach and debugging before.
Finally, let's assign some shortcut commands to Attach to process and reattach:
Using the same technique as last time:
- Search for Debug.AttachtoProcess and assign Alt+W
- Search for Debug.ReAttach and assign Alt+Q
Now you can first find your correct process under Alt+E, then attach to it using Alt+W and finally reattach using Alt+Q.
Maybe you want different shortcuts, feel free to do it your way.
Do you often find yourself trying to attach to the correct w3wp process in order to debug your web application? No more!
There's an excellent Visual Studio extension out there called ReAttach. It let's you magically reattach to the latest debugged process.
Download ReAttach extension
Once you've installed ReAttach, make sure to use its inbuilt shortcut or create your own. I added my own as Alt+R in Visual Studio:
Tools->Options->Keyboard->Search for reattach and assing Alt+R shortcut
Also it helps if you know what w3wp process to attach to in the beginning. Use the list wp command under Visual Studio tools for this. Read more on finding the right web process at the Nansen blog.
Make Add-ins show up in Visual Studio 2010.
Have you installed Visual Studio Add-ins recently but they don't show up anywhere? Well, there's a solution!
I recently ran into this problem where the add-in Git Extensions was installed and did work for earlier Visual Studio versions - but Git didn't show up in the toolbar in Visual Studio 2010.
Some Googling and there still wasn't an answer. Until now. It turns out the Visual Studio Add-Ins (Git Extensions in this case) weren't allowed to load.
Here's how to fix it:
- Go to Tools->Options->Environment and choose Add-in/Macros Security
- Make sure Allow Add-in components to load is ticked and press Ok
- Restart Visual Studio and Git should now be visible in the toolbar!
When trying to debug in Visual Studio, you get the following error:
Breakpoint will not currently be hit. No symbols loaded for this document.
After some research, I came up with a solution: delete temporary ASP.NET files. This is how you do it:
- Locate your temporary ASP.NET files and delete them. They're probably located in C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files.
- Rebuild your project and attach to process and you should be fine - the breakpoint should be hit.
I recently ran into a minor problem with my Visual Studio theme - the current line was highlighted and because of that I had quite a hard time reading the code and comments on the specific line.
Since I've been dealing with Visual Studio themes a bit lately, I knew how to change the theme colours, via Tools -> Options -> Environment -> Fonts and Colors. However - there are quite a lot alternatives to go through and it isn't always easy to find which alternative corresponds to what Visual Studio theme setting.
Then I found how you could change the appearance of the current line. This is how:
- Find the Current Line (extension) and Current Line Inactive (extension) rows.
- Change foreground and background.
This is how it could look:
Now, most of the Visual Studio users might not have those rows under Fonts and Colors. This is because the Productivity Power Tools must be installed.
The Productivity Power Tools will not only give you more control over Visual Studio's current line, but much more. If you're a serious Visual Studio developer, install the tools!
(Thanks to Patrik Totero for providing me with the Visual Studio theme)
I recently stumbled upon a problem where some Visual Studio templates wasn't available when I choose Add new item in Visual Studio.
I needed to generate some LINQ to SQL classes, but the Data alternative wasn't there.
After some searching, here's what solved the problem:
For Visual Studio 2010, find the VS command prompt (in the start menu), right click it and choose 'Run as administrator'. Execute this command:
You won't be noticed if anything succeeds or fails, but you should now have the appropriate Visual Studio templates available in the Add new item menu.
For Visual Studio 2008, I solved the problem by re-installing Visual Studio 2008 Service Pack 1.
Also, you can have a look in the C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates folder to see what's missing. You can even copy zip files from other Visual Studio installations to the folders here and execute the above command for Visual Studio 2010, and get it working.
Also - there's a difference when adding files in Solution Explorer, compared to through the File menu.
Here are some blog posts and stack overflow posts that helped me:
If you, like me, like to take a deep plunge into Visual Studio debugging, you might've encountered the dreaded Web server process termination error, "The web server process that was being debugged has been terminated by Internet Information Services":
It's very irritating when you're in the middle of a debugging session and it's stopped by the error message above. But - there's a solution! As the error message tells us, you can configure application pool settings in IIS.
This is how to do make sure you'll be able to debug forever:
- Pop up your IIS and find the correct Application Pool
- Right click and choose Advanced Settings
- Below Process Model, find Ping Enabled and make sure it says False:
Here are a couple of quick steps that will make your Visual Studio faster (particularly 2005 and 2008 version):
Turn off AutoRecover
Under Tools->Options->Environment->AutoRecover, untick Save AutoRecover information every.
This turns off the AutoRecover mode, which makes sure you quickly can get crashed Visual Studio instances back.
Turn off animations
Under Tools->Options->Environment, untick Animate environment tools.
Turn off track changes
Under Tools->Options->Text Editor, untick Track changes.
Track changes is used to tell you what section of the code you've recently edited.
Turn off the Visual Studio start page
Under Tools->Options->Environment->Startup, choose the alternative Show empty environment under At startup.
Install the latest service pack
It's always a great idea to have the latest service pack installed. Download Service Pack 1 for Visual Studio 2008.
Visual Studio sometimes points out that HTML and CSS in a project doesn't validate, showing the dreaded Error list with errors and warnings.
This is one of the most annoying things about Visual Studio, since it becomes harder to find real compilation errors in the error list. Plus, it's better to use the web browser and add-ons (e.g. Firefox with the HTML Validator add-on) to find validation errors.
This is how the error list might look in Visual Studio, pointing out validation errors:
How to turn off validation errors in Visual Studio
- In Visual Studio, go to Tools->Options and expand the node Text Editor.
- To turn off HTML validation, expand the node HTML, choose Validation and untick Show errors under Options. Press Ok.
- To turn off CSS validation, expand the node CSS, choose CSS Specific and untick Detect errors under Errors. Press Ok.