Installing additional Virtual Directories in a Web Setup Project

A Visual Studio Web Setup Project (or Deployment Project) lets you define the contents of a Web Application Folder by adding Content Files and Primary Output of a Web project in the File System view.

Additionally, using the menu command Add Special Folder/Web Custom Folder, one can add more web directories to the setup project, which will end up in the file system under c:\inetpub\wwwroot and will define a separate IIS application for each folder.

In one of my projects I needed to add additional Virtual Directories located at web root and pointing to subdirectories of the web app located in the Web Application Folder. (some URLs generated by the app were root-based, and will be cleaned up, so please don’t ask)

This can accomplished by creating an installer class derived from System.Configuration.Install.Installer, and using one of the many APIs available to administrate IIS (MSDN on IIS 6, MSDN on IIS 7). The project containing the installer class must be added to the setup project’s File System view.

I chose to use the MSDN sample to create Virtual Directories using System.DirectoryServices.DirectoryEntry as described in my previous post. The installer class is called by the web installer using the Custom Actions mechanism.

The find the physical location of the installed directories, you can either derive the path information from Assembly.GetExecutingAssembly().FullName or by passing the installation directory as a parameter to the Custom Action.

  • Custom Actions
  • Install
  • Primary output from MyWebInstaller
  • CustomActionData /targetdir=[TARGETDIR]

You can name the parameter as you like, but the [TARGETDIR] is a pre-defined web installer property.

The parameter is accessed via the Context.Parameters collection in the installer:

var targetdir = Context.Parameters["targetdir"];

This value is used to create the virtual directory in web root:

const string WebRoot = "IIS://";
CreateVDir(WebRoot, "MyRootDir", targetdir.Replace(@"\\", @"\") + "MyDir");


  • This post has a complete walk-through on web setup projects and custom actions.

One Response to Installing additional Virtual Directories in a Web Setup Project

  1. […] I created a Web Setup project in Visual Studio 2010 for a .Net 4 web application to install on a Windows 2008 Server running IIS 7. The prerequisite knowledge is described in my previous posts. […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: