Add Virtual Directory programmatically, for easy “new-box” deployment.

I’m always trying to make my project deployment as easy as possible.

 

One of the “problems” I’ve encountered is keeping my solution structure, that is:

– MySolutionDirectory

      – MyWebProject

      – MyBusinessLayerClassLibrary

      – MyDataAccessLayerClassLibrary

      – MyEntitiesClassLibrary

      – etc.

 

This is hard to do, especially when the “Add Web Project” creates a virtual directory in

my wwwroot directory by default which breaks my desired structure.

 

When I want to initialize the Solution or to pull the entire solution from the

VSS (e.g – on a new programmer station) I need to take these steps beforehand


  1. Create the directory [solution-path]\[web-project\webservice name]
  2. Go to my IIS and add the required virtual directory which will redirect to step 1 path.

Otherwise, the VS.NET will create the web folders in my wwwroot automatically, which will again break my preferred structure.

In addition, in some of my solutions, I have more than 1 web project\webservice and repeating these steps can get very annoying.

 

So, after reading about IIS API, I’ve created an IIS helper utility for creating virtual directories by

demand in one-click EXE.

 

The configuration file is quite simple:


<VDSettings>
    <Directories>
        <Directory>
            <DirectoryPath>C:\Projects\MySolution\MyWebProject</DirectoryPath>
            <VirtualDirectoryName>MyWebProject</VirtualDirectoryName>

        </Directory>
        <Directory>
            <DirectoryPath>C:\Projects\MySolution\MyWebShareProject</DirectoryPath>
            <VirtualDirectoryName>MyWebShareProject</VirtualDirectoryName>
            <CreateUnder>MyWebShareProject</CreateUnder>
        </Directory>
    </Directories>
</VDSettings>


This sample demonstrates how to add “MyWebProject” Virtual Directory and create another

Virtual Directory, under “MyWebProject”, named “MyWebShareProject”.

 

* 2 Notes:


  1. You can create the virtual directory under a WebSite by using “WebSiteName” element under the “Directory” element.
  2. If the “DirectoryPathdoesn’t exist – the utility will create it before setting the Virtual Directory path.

 

Now, when a co-worker in my company is trying to deploy my solution on his station, all he needs to

do is to run VDCreator.exe and he can continue the deployment via VS.NET -> “Open From Source Control…” option.

 

That’s what I call “child’s play” deployment.

 

The files:

VDCreator bin1.zip (4.62 KB)  (EXE & config file only)

VDCreator Source.zip (9.64 KB) (Source files included)

 

Oren Ellenbogen

 

One thought on “Add Virtual Directory programmatically, for easy “new-box” deployment.

  1. <CreateUnder>MyWebShareProject</CreateUnder>

    should be

    <CreateUnder>MyWebProject</CreateUnder>

Comments are closed.