Adding and removing IIS7 Virtual Directories

Jul 1, 2010 at 6:54 PM
Edited Jul 1, 2010 at 7:02 PM

I'm attempting to add a task to my MS Build project that will remove a virtual directory (if it exists) from the default web site and then create the virtual directory again (also on the default web site).  We had been using the MSBuild.Community tasks and IIS6, but they haven't been updated to support IIS7.

The MSBuild Extension Pack help doesn't include an example for the AddVirtualDirectory task action and there doesn't appear to be a way to delete a virtual directory - the only task action for deletes appears to only delete a site.

If I add the following to my MSBuild targets file and call the DeployToWeb target:

    <MyVirtualDirectory Include="/MyVdir">
      <ApplicationPath>/Default Web Site</ApplicationPath>

  <Target Name="DeployToWeb">
    <MSBuild.ExtensionPack.Web.Iis7Website TaskAction="Delete" Name="MyVdir" ContinueOnError="true"/>

    <MSBuild.ExtensionPack.Web.Iis7Website TaskAction="AddVirtualDirectory"
                                           Name="Default Web Site"

I get the following output from MSBUILD:

C:\projects\Test\buildtest.targets (,): warning : The website: MyVdir was not found on: BRE0106
Adding VirtualDirectory: /MyVdir to: /Default Web Site
MSBUILD (,): warning : NullReferenceException: Object reference not set to an instance of an object. [C:\projects\Test\buildtest.targets]
MSBUILD (,): warning : [C:\projects\Test\buildtest.targets]

The first error makes sense as I haven't successfully created the virtual directory yet, and I'm not expecting that the Delete task action will work to delete a virtual directory anyway.

But given the limited help documentation, especially for AddVirtualDirectory, and minimal information in the error, I honestly have no idea what I'm doing wrong to add a virtual directory to the default web site.

Any assistance would be appreciated.

Jul 1, 2010 at 7:31 PM

Changing the item group to:

    <MyVirtualDirectory Include="/MyVdir">

Seems to create the virtual directory named MyVdir under the Default Web Site - I obviously had the application path set incorrectly.  Unfortunately, it isn't serving up any content - I just get a blank view in the browser and view source shows essentially an empty page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>

Jul 1, 2010 at 8:24 PM

what type of content are you trying to browse? does a basic .htm page display?

Jul 2, 2010 at 3:07 PM
mikefourie wrote:

what type of content are you trying to browse? does a basic .htm page display?

Thanks for your reply and sorry for the delay in answering your questions.

It's our internal ClickOnce site - for rendering purposes it's just a basic html page with some inline styles and a few javascript functions.  It's not an app or anything.  One complication is that my development box is Server 2003 / IIS 6 and the problem is happening on a build server that I don't have access to (running Server 2008 / IIS 7).

I copied the virtual directory contents to my personal Windows 7 / IIS 7 system at home and created the virtual directory through the management console (I simply created a virtual directory, assigning it an alias name and the path for the contents - everything else was left at default settings) and the page renders just fine.  I'm now trying to set up a scaled down version of the msbuild script on that system so I can test creation of the virtual directory and actually see what's getting created in the management console.  Getting our entire solution setup on my own personal system would be a non-trivial project, so if I can't resolve this today, I'll rebuild one of my systems at work with either Windows 7 or Server 2008 next week so I can proceed more easily.

Naturally our release engineering team updated the build server from 2003 to 2008 without giving us any notice...

Jul 2, 2010 at 3:14 PM

The scaled down version of the build script creates the virtual directory on my personal Windows 7 box and the content renders just fine so there must be a problem with our build server configuration.  As I expected, the Delete task action does not remove the virtual directory - if there's a way to do it, I'd appreciate the info on how to do so.

Jul 5, 2010 at 2:04 PM

That's odd. I don't think the extension pack offers that. I'll add it in tonight if that's right.


Jul 5, 2010 at 2:16 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.