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
by passing the installation directory as a parameter to the Custom Action.
- Custom Actions
- Primary output from MyWebInstaller
- CustomActionData /targetdir=[TARGETDIR]
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://127.0.0.1/W3SVC/1/Root"; CreateVDir(WebRoot, "MyRootDir", targetdir.Replace(@"\\", @"\") + "MyDir");
- This post has a complete walk-through on web setup projects and custom actions.
- Web directories and virtual directories are not removed from IIS during uninstall. If you need this functionality, you also have to implement it as a Custom Action.