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.

100 Comments

Comments have been disabled for this content.