Saturday, 7 April 2007

Changing the default startup project preference

By default, visual studio sets the first project that you add to a solution as the startup project when you hit the Debug-->Start (F5) or Debug-->Start without debugging options (ctrl-F5). This can be particularly annoying, especially when developing client server applications. You may want to start the server first, then when it is listening, start the client. You may want to start multiple projects at the same time. Now these options are available by right clicking on the solution and selecting Properties, Common Properties-->Startup Project.

By default single startup project is selected and the project currently in the drop down is what visual studio will try and start. I have recently acquired a taste for current selection (when you have are writing unit tests it is particularly handy for quickly running the current test project).

You can change the default for this by navigating to tools-->options-->Environment-->Projects and Solutions-->Build and Run. And there tick the check box "For new solutions use the currently selected project as the start up project". If you have a large solution it may also be worth checking the "Only build startup projects and dependencies on run" in order to avoid building everything to run some low level test.

Incidently, changing the default startup options doesn't just effect new solutions as the name suggests, it will effect any solution that doesn't have an options file (solutionname.suo). This means that in a team environment, as long as everyone has their own solution option files, changing this option will not effect other users.

Wednesday, 4 April 2007

Xml attribute formatting

If you spend a lot of time formatting your xml documents with each attribute lined up on a seperate line, you will be pleased to know that there is an option in VS 2005 which allows you to do this automagically.

Tools-->Options-->Text Editor-->Xml-->Formatting

switch the radio button to "Align attributes each on a seperate line".

then ctrl-k, ctrl-d your way to easy to read xml files.

Most useful when something updates your xml for you, like updating a WCF service reference.

Tuesday, 3 April 2007

First Post

Well, it has been a long time in finally making it out the door, but today I realised that I may have something useful to contribute to the world after all. So here goes, first blog post (for me) ever!

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". Well it is... and it isn't

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.

If you know how to switch it off it is easy, if you don't, it is undocumented and google doesn't quite get the answer.

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:


  1. Backup your current visual studio settings (follow step 1..9 but select everything in step 6)
  2. Visual Studio --> Tools Menu
  3. Select Import and Export Settings...
  4. Select the "Export selected environment settings" radio button (default)
  5. Hit "Next"
  6. Make sure you have "All Settings"-->"Options"-->"Text Editor"-->"C# Editor" checked.
  7. Hit "Next"
  8. Select a file name and location
  9. Hit "Finish"
  10. Open the file in your pet xml editor
  11. Search for "ImplementInterface_InsertRegionTags"
  12. change the value to 0 (zero)
  13. Save the change
  14. Repeat steps 1 and 2
  15. Select the "Import selected environment settings" radio button
  16. Select "No, just import the new settings, overwrite my current settings"
  17. Hit "Next"
  18. Select or browse for the file that you made the changes to
  19. Hit "Next"
  20. Make sure you have "All Settings"-->"Options"-->"Text Editor"-->"C# Editor" checked.
  21. Hit "Finish"
  22. Restart Visual Studio (optional I think, seemed to work without it)
  23. Implement interfaces without regions :)

Note: This passed the "it works on my machine" test, but I make no guarantees.