This week I have been on a wcf course with DevelopMentor. Today when the instructor Dominick Baier, was deleting for the umpteenth time the "#region" tags (these are inserted when you use the smart tag in Visual studio 2005 to implement an interface) I smiled to myself, because this is one of my pet hates too. Then he said "does anyone know how to switch this off?", and I thought to myself "it can't be that hard".
Actually, it turns out my way is the really hard boring way. As Steve pointed out in the comments, if you go to tools-->options-->text editor-->c#-->advanced then there is a "Surround generated code with #region" checkbox. This is clearly the easy way! Thanks Steve
If you are looking for how to change the default startup settings for a solution you need to head here.
I found a pointer in one of the comments here. Needless to say the registry key is a red herring for the rtm version of Visual Studio 2005. In fact I couldn't even find the full path in the registry, which got me to thinking "where did they move all this config if it isn't here anymore"? Well one of the nice features of Visual Studio 2005 is that you can export your user settings. One of the things I remembered thinking, when I exported my settings was, "There is a lot more being exported than I see in the UI". Turns out that "ImplementInterface_InsertRegionTags" is exported with a value of 1. if you export your settings, set the value to 0 (zero) and (re)import the settings again, the "#region" tags disappear :)
So the exact steps:
- Backup your current visual studio settings (follow step 1..9 but select everything in step 6)
- Visual Studio --> Tools Menu
- Select Import and Export Settings...
- Select the "Export selected environment settings" radio button (default)
- Hit "Next"
- Make sure you have "All Settings"-->"Options"-->"Text Editor"-->"C# Editor" checked.
- Hit "Next"
- Select a file name and location
- Hit "Finish"
- Open the file in your pet xml editor
- Search for "ImplementInterface_InsertRegionTags"
- change the value to 0 (zero)
- Save the change
- Repeat steps 1 and 2
- Select the "Import selected environment settings" radio button
- Select "No, just import the new settings, overwrite my current settings"
- Hit "Next"
- Select or browse for the file that you made the changes to
- Hit "Next"
- Make sure you have "All Settings"-->"Options"-->"Text Editor"-->"C# Editor" checked.
- Hit "Finish"
- Restart Visual Studio (optional I think, seemed to work without it)
- Implement interfaces without regions :)
Note: This passed the "it works on my machine" test, but I make no guarantees.
3 comments:
I think you can also do this within the UI - go to Tools / Options, and then to Text Editor / C# / Advanced. In there, there is a "Surround generated code with #region" checkbox, which I think is what you've after
so you can!
I searched for that and just didn't see it. I will update my post.
The spooky thing is that I've also spent the last few years manually deleting the damned #region blocks, and stumbled across the setting, purely by accident, just yesterday.
Post a Comment