Scott on Writing

Musings on technical writing...

Quickly Opening a Visual Studio Website Project

On my computer I have a directory called Tutorial Sites and under that directory have a subfolder for various file system-based ASP.NET 2.0 websites I create to either have as a playground of sorts, to try out some new fangled feature of 2.0, or as a demo for class or article. What's kind of annoying is the process of creating and opening these sites. Yes, it's a lot quicker than creating a vdir in IIS and doesn't clutter the website metabase, but to create a file system-based website I need to launch VS 2005, click Open Website, then tinker down to the directory and choose a name. To open one, I have to do the same.

Most of the time I find myself using Windows Explorer to navigate around the file system. What I'd really like to be able to do is just right-click on a folder and say, “Open as Website” and, poof, Visual Studio would open and load that website. Clearly this makes opening an existing website as easy as pointing and clicking; to create a new website I'd just create a new folder through Windows Explorer, then open it in VS through the context menu.

Today I finally decided to stop wishing, invest some time, and actually get something that works. Here's what I tried:

  • Visual Studio can be launched through the command-line by running devenv.exe. Therefore, my exploration started with examining devenv.exe's command-line switches. With an existing Solution or Project file, you can pass in the project or solution file and, voila, it will open. However, I didn't want a dependence on a project file - I just wanted to be able to right-click on a folder in Explorer and say, “Open as Website.“
  • I did notice that VS can accept commands through the command-line switch. Commands can be activated through the Command Window in VS and allow for interacting with the GUI. For example, you can do File.OpenWebSite. However, this just pops up the Open Website dialog box - you still have to pick a file to open. And, sadly, you can't pass in an argument to this particular command. Shucks.
  • I then though that maybe macros would solve my problem. I probably spent far too long poking through what little macro documentation I could find. Is there not a one-stop reference for the macro API?
  • After banging my head on macros for a while, I decided to try something new, and ended up with a solution that works for me, but is a bit 'messy,' as you'll see in a moment.

Since Visual Studio will let you open a solution or project file passed through the command-line, I ended up writing a managed command-line program that could be passed the folder path of the website to open and a folder path to place a project file. This program would then create an actual project file and then launch devenv.exe, passing in this just-created project file.

What I don't like about my approach is that:

  • It creates these 'garbage' project files that never get deleted unless you do so manually. Granted, these files are like 1-2KBs in size and can be tucked away in a directory out of sight, but it still feels dirty to do this.
  • Second, I don't know how to get the path to devenv.exe, so the program has the path hard-coded (C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe). The program does accept an optional third input parameter, though, that can be used to specify the path to devenv.exe.

The complete code can be downloaded here. Once you have the code downloaded and compiled, to add the “Open as Website” option to the Windows Explorer context menu you'll need to run the .reg file included in the download. This adds a registry entry in HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\ that runs the program, passing in the path folder of that was just right-clicked. You will need to customize this .reg file before you run it, putting in the path to the program. You'll also need to specify the path to dump the project files. I chose the folder C:\Documents and Settings\Scott\My Documents\Visual Studio 2005\Projects\TempWebsiteProjects, but any path should suffice.

If you have any ideas or know-how on how to improve this, or run into any problems, please don't hesitate to post a comment to this blog entry. Special thanks to Chris Frazier and Robert McLaws, who both developed a “Start the ASP.NET 2.0 Development Web Server“ concept on their own. More info at Robert's “ASP.NET 2.0 Web Server Here“ Shell Extension.

Enjoy!

posted on Monday, December 05, 2005 6:42 PM

Feedback

# re: Quickly Opening a Visual Studio Website Project 12/6/2005 5:15 AM Thomas Freudenberg

AFAIK the path to devenv.exe is "%VS80COMNTOOLS%..\IDE\devenv.exe"

# re: Quickly Opening a Visual Studio Website Project 12/6/2005 11:07 AM Steve Ewart

You can get the location of the IDE from the registry. In 2003 it is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\InstallDir

Steve

# re: Quickly Opening a Visual Studio Website Project 12/6/2005 5:35 PM Brian B

I hope you will send this feature to one of your Microsoft contacts so one of the gurus can make a change to VS or whatever needs to be done. This would be awesome!

# re: Quickly Opening a Visual Studio Website Project 12/6/2005 5:42 PM Scott Mitchell

Steve & Thomas - thanks for the pointers!

Brian, ASP.NET Team Member danmor replied to my ASP.NET Forums post [http://forums.asp.net/1134110/ShowPost.aspx] and noting that he'd "open a suggestion bug on it." SO hopefully that leads to this capability being 'baked in' in the next version of VS.

# re: Quickly Opening a Visual Studio Website Project 12/9/2005 10:10 AM Michael Bundschuh

FYI, I made sure we recorded this suggestion and it will be considered for Orcas. No promises, but we will consider it. :-)

-Mike-

# re: Quickly Opening a Visual Studio Website Project 12/9/2005 2:58 PM BradleyB

Hey Scott, here is a sample that will do the same thing with a macro.

http://weblogs.asp.net/bradleyb/archive/2005/12/09/432802.aspx

# re: Quickly Opening a Visual Studio Website Project 12/9/2005 7:28 PM Brian

It works and it is awesome. Thanks BradleyB!

# re: Quickly Opening a Visual Studio Website Project 12/18/2005 10:22 AM Bob Archer

If your web site is part of a solution, can't you just double-click on the sln file?

BOb

# re: Quickly Opening a Visual Studio Website Project 12/18/2005 4:02 PM Scott Mitchell

Bob, you can do that. My solution is for if you have some file on your hard drive that you want to open as a website in VS 2005. This little tool (or Bradley's) makes it a breeze to accomplish this, saving a few precious clicks in opening VS then opting to open a website...

# Toolbox: Öppna ett webbprojekt med ett högerklick 12/21/2005 5:59 AM André Henriksson

En sak jag saknat med Visual Studio 2005 är möjligheten att direkt kunna öppna ett webbprojekt från en...

# re: Quickly Opening a Visual Studio Website Project 12/31/2005 2:46 AM Tarun

Thanks Scott

# Lookin 4 HELP 1/8/2006 6:07 AM spider-man

Hey guys , this must be quite simple for you.

I have opened a project originally buid in another pc machine.

The point is this...
In Design Time I see all this controls inside my only Form. This is correct
BUT, At Run time my only form shows itself as a simple new form, I mean like a new project with size and no control by default...

I thought at first it was about the name space, but this change does not make results for me...

I don´t want to re.buid the entire application, Also, everithing has a solution isn´t?

Title:  
Name:  
Url:
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments   

Add To Your Reader

My Links

Archives

Post Categories

 

I am a Microsoft MVP for ASP.NET.
I am an ASPInsider.
<May 2008>
SMTWTFS
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

Comment Stats

DayTotal% of Total
Sunday 1866.8%
Monday 37913.9%
Tuesday 45316.7%
Wednesday 50418.5%
Thursday 53519.7%
Friday 49418.2%
Saturday 1666.1%
Total 2717100.0%

Hour1Total% of Total
12:00 AM 652.4%
1:00 AM 682.5%
2:00 AM 622.3%
3:00 AM 742.7%
4:00 AM 572.1%
5:00 AM 1033.8%
6:00 AM 1084.0%
7:00 AM 1585.8%
8:00 AM 1716.3%
9:00 AM 1475.4%
10:00 AM 1716.3%
11:00 AM 1816.7%
12:00 PM 1886.9%
1:00 PM 1696.2%
2:00 PM 1605.9%
3:00 PM 1324.9%
4:00 PM 1073.9%
5:00 PM 923.4%
6:00 PM 913.3%
7:00 PM 963.5%
8:00 PM 833.1%
9:00 PM 782.9%
10:00 PM 792.9%
11:00 PM 772.8%
Total 2717100.0%

Comments by Blog Entry Date/Time

Day Entry MadeAvg.Total
Sunday 5.54144
Monday 5.22339
Tuesday 4.28419
Wednesday 7.67637
Thursday 6.90607
Friday 5.48411
Saturday 5.33160
Total 5.842717

Hour1 Entry MadeAvg.Total
12:00 AM 5.0035
1:00 AM 1.002
5:00 AM 0.000
7:00 AM 7.0035
8:00 AM 5.35107
9:00 AM 6.32278
10:00 AM 6.47246
11:00 AM 4.41181
12:00 PM 6.88330
1:00 PM 3.00111
2:00 PM 5.41222
3:00 PM 8.64285
4:00 PM 4.0589
5:00 PM 5.92154
6:00 PM 4.52113
7:00 PM 9.67174
8:00 PM 9.80147
9:00 PM 5.05111
10:00 PM 5.4265
11:00 PM 4.5732
Total 5.842717

Learn More About Comment Stats
1 - All times GMT -8...


Blog Stats

Favorite Web Sites

My Books

My MSDN Articles