BradleyB's WebLog

How to open a website in Visual Studio 2005 from the command line

I’ve seen several queries asking how to launch Visual Studio 2005 opening a specific folder as a website from the command line.  Unfortunately Visual Studio 2005 does not support this by default but you can enable the scenario by writing a macro.

 

To do this, create a new macro either in an existing module or in a new module.  For this example I’m going to add a module call Website to the MyMacros project.

 

If you’re new to macros in Visual Studio 2005, select menu Tools/Macros/Macros IDE, then select the MyMacros project and add a module.

 

Before you can use the new Website extensibility objects within VS you’ll need to add a reference to VsWebSite.Interop.dll. 

 

Once added you can add the following code:

 

Public Module Website

    Sub OpenWebsite(Optional ByVal path As String = "")

        If (String.Compare(path, String.Empty) = 0) Then

            MsgBox("Must supply a folder path to the OpenWebsite macro", MsgBoxStyle.OkOnly)

        Else

            Dim webPkg As VsWebSite.VSWebPackage

            webPkg = DTE.GetObject("WebPackage")

            webPkg.OpenWebSite(path, VsWebSite.OpenWebsiteOptions.OpenWebsiteOption_None, False)

        End If

    End Sub

End Module

 

 

After this code is added you’ll be able to run the macro.  You can test it out in the command window.

 

From the Command Window in VS:

 

>Macros.MyMacros.Website.OpenWebsite C:\MyProjects\MyCompany\CompanySite

 

From the Command Line:

 

devenv /command "Macros.MyMacros.Website.OpenWebsite C:\MyProjects\MyCompany\CompanySite"

 

After its working you can register a shell command enabling an “Open as Visual Studio Website” command on any folder in windows explorer.

 

To do this copy the following into a OpenWebsite.reg file and run it.

 

Windows Registry Editor Version 5.00

 

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\OpenVSWeb]

@="Open as Visual Studio Website"

 

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\OpenVSWeb\command]

@="devenv.exe /command \\\"Macros.MyMacros.Website.OpenWebsite %1\\\""

 

 

Now you should be able to right click on a folder in Windows Explorer and select “Open as Website”.

 

Hope this helps,

Brad.

Comments

Brian said:

This is awesome! Thanks!!!
# December 9, 2005 10:28 PM

Zubair.NET! said:

Awesome, it works!
# December 11, 2005 12:11 AM

MaheshKumar.R said:

Really usefull and good work..
thanks brad..
# December 12, 2005 4:42 AM

vFramer said:

COOOOOOOOOOOOOOOOOOOOOOOOOOL!
# December 14, 2005 9:47 AM

oVan said:

Thank you for this great tip!
# December 19, 2005 9:36 AM

Zubair.NET! said:

Any ideas on how to implement it in VS2003/2002 given that the website is already configured in IIS.

Zubair.NET!
http://zubairdotnet.blogspot.com
# December 21, 2005 11:19 PM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# July 26, 2006 6:39 AM

.net DEvHammer said:

Ever wanted to be able to simply right-click a folder in Windows Explorer and open it as a web site in...

# August 14, 2006 9:02 PM

Tech Guru said:

# August 14, 2006 10:45 PM

Йордан Димитров said:

Вече има и SP 1 за Microsoft® Visual Studio® .NET™ 2003 download. CTP на нoватаверсия на ADO.NET...

# August 17, 2006 1:09 AM

Frederic said:

I Love You :-)

# September 8, 2006 11:21 AM

johnagrandy said:

My VS05 does not have a Tools/Macros menu ...

Any ideas ?

# October 6, 2006 12:50 PM

az said:

My cat's breath smells like cat food

# April 24, 2007 5:28 PM

Suraj Kumar said:

This is helpfull.

Thanks,

# July 29, 2007 5:08 PM

James Reid said:

I'm new to adding references in VS. How do you add a reference to VsWebSite.Interop.dll?

# November 12, 2007 1:13 PM

mensah kelvin said:

this website will bring lost friends together

# February 1, 2008 3:06 PM

anupama reddy said:

Dear sir,

        I want to open my website. How to proceed? Can u help me?

Thanks & Regards

Anupama Reddy

# March 21, 2008 7:55 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)