Dan Rigsby – Coding Up Style

Developer.Speaker.Blogger

How to open a project file in Visual Studio 2008 for editing

Posted by Dan Rigsby on April 11th, 2008

How many times have you opened up a .csproj file and wanted to edit the xml, but it opened up the actual project in Visual Studio instead?  Your only real options have been:

  1. Open the project file in a different text editor
  2. Give the project file a new extensions, then open it in Visual Studio
  3. Use some custom visual studio extension or write your own

Microsoft released a set of PowerCommands for Visual Studio 2008 which provides this functionally.  With this you can just right click on the project and select “Edit Project File”:

PowerCommands1

This will open the project file in the visual studio xml editor. This makes it so much better than an external editor because it allows for intellisense through the xsd schema (http://schemas.microsoft.com/developer/msbuild/2003)!

PowerCommands2

Notice though that while you are editing the project, it becomes unavailable in the Solution Explorer.  This is a side affect, because if you are editing the file, Visual Studio can’t yet know what it is going.  So, when you are done editing the file, you have to right click on the project in Solution Explorer and reload, or close the xml editor and reload the project. It would have been nice if it could have just detected when the project file was changed and then asked the user if he/she wanted to reload the project now.  This would be consistent with what you see if you edit the project file in an external editor.

The PowerCommands collection contains a number of other enhancements which you can see on the project website.  Some of my favorites are:

  • Copy and Paste References: Allows you to copy to the clipboard a project reference or set of references and paste them into another project
  • Copy and Paste Class: Allows you to copy a class to the clipboard which renames the class and to paste it into the project again.
  • Open Containing Folder and Open Command Prompt: Allows you to right click on a file and open the folder or a command prompt at that location
  • Remove and Sort Usings: We got this feature in VS 2008 itself, but you can now run this at the project level to affect all files at once.  Now I wish I could do this with “Format Document” too.
  • Close all documents context menu item:  Allows you to close all open documents.  Sometimes when the designer is getting “funky”, I like to close all files, rebuild, and open it again.  Before I could only “Close all but this” and then close that last document.  With this new command, I can close all of them at once finally!
  • Transform Templates: Allows you run execute a “custom tool” with associated text template items.

I highly recommend that you download these free tools from Microsoft.

Download PowerCommands for Visual Studio 2008 here: http://code.msdn.microsoft.com/PowerCommands

kick it on DotNetKicks.com

One Response to “How to open a project file in Visual Studio 2008 for editing”

  1. Bob Uva Says:

    thanks Dan! I had downloaded the PowerCommands a week ago but haven’t explored them much. Being able to edit the csproj in xml is awesome.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>