Search...

1 September 2009

Howto open a Visual Studio file from an application into a running Visual Studio instance.

I have a little utility application that I have been working on for some time which is used to edit our applications .config files (note these are essentially the <appSettings> section from our web.config wrapped into client specific files). For a while I was struggling to solve what I thought was a simple issue. That was that I wanted to set the application as the default tool to open the .config files with within Visual Studio (right click on a file and Open With, this will let you set a tool to open the file with and even set it as the default).

The problem started when I next went to open the default web.config and it obviously tried to load it via my application (which does not handle the default web.config).

I amended the Main() method of my application to check for the file name (crude but it works) and only continue loading the file passed via the command line arguments if it matched a set patten. That worked..... kind of!!

The trouble was when ever the application came across a file it did not want to handle it would, as designed, open the file in Visual Studio. However, rather than in the running instance of Visual Studio it always opened a new instance of the application.

After much digging about and Spy'ing I discovered that you have to pass the /EDIT parameter to DEVENV to have the file open in a running instance. So DEVENV /EDIT $FileName is the pattern.

No comments: