In this article we will see how to interact with IIS in the installer and how to add new website or new web application to existing website.

Adding support for IIS

To add support for IIS on the WiX part:

  1. Right click on Package project, select Add->New Item... menu entry and in the Add New Item dialog select "IIS website/application feature", select name (eg. Product.Website.wxs) and click Add.
  2. Go to Product.Feature.wxs file and add <ComponentGroupRef Id="Website.ComponentGroup" /> in appropriate feature tag (eg. MainFeature).
  3. Note that new file may be added to Website.Files component or you may create additional components.
  4. To add web.config file create a file named web.config in ProductBuild folder with the following contents:
    <?xml version="1.0"?>
    <configuration>
      <connectionStrings>
        <add name="MyConnectionString" connectionString=""/>
      </connectionStrings>
      <system.web>
        <compilation debug="true" targetFramework="4.0"/>
      </system.web>
    </configuration>
  5. Go to Product.Website.wxs file, define util XML namespace (xmlns:util="http://schemas.microsoft.com/wix/UtilExtension") and add the following code under DirectoryRef element with Id set to Website.WebApp:
    <Component Id="Website.web.config">
            <File Id="File.web.config" Source="..\ProductBuild\web.config" />
            <util:XmlFile
              Id="web.config.connstr"
              File="[#File.web.config]"
              Action="setValue"
              ElementPath="//configuration/connectionStrings/add[\[]@name='MyConnectionString'[\]]/@connectionString"
              Value="Data Source=[SQL_SERVER]; Initial Catalog=[SQL_DATABASE]; User Id=AppLogin; Password=[RANDOM_PASSWORD]"
              />
          </Component>
  6. Go to definition of Website.ComponentGroup and add reference to the newly created component by adding the follong line:
    <ComponentRef Id="Website.web.config"/>
  7. Right-click on Package project node in Solution Explorer and select Update Translation item.
  8. Note steps below to handle the RANDOM_PASSWORD property correctly.

 

To add the GUI to support IIS:

  1. Right click on the Gui project, select Add->New Item... menu entry and in the Add New Item dialog select Visual C# Items->SharpSetup->WinForms/WPF in left hand side tree and then IIS website/application dialog in the right hand side list. Select name (eg. WebsiteStep.cs or WebsiteStep.xaml) and click Add.
  2. Go to SetupWizard.cs file (source code) and add AddStep(new WebsiteStep()); code line in appropriate places (eg. in InstallationMode.Install and InstallationMode.Upgrade sections of LifecycleAction method).
  3. Go to InstallationStep.cs file and add the following two lines just before PrerequisiteManager.Instance.Install() call:
    Globals.SetVariable<string>("SAPWD", GeneratePassword());
    MsiConnection.Instance.SetProperty("RANDOM_PASSWORD", GeneratePassword());
  4. Add the definition of GeneratePassword method to InstallationStep class:
    string GeneratePassword()
    {
        var randomness = new byte[20];
        new System.Security.Cryptography.RNGCryptoServiceProvider().GetBytes(randomness);
    return Convert.ToBase64String(randomness);
    }
  5. Build and test the installer.