WiX - Copy the compiled environment based web.config for the root website

As part of my WiX installation, I copy all the converted / compiled web.config files to the installation directory. The names of the compiled web.config are in web format. {ENV} .config. In my install UI, I created a custom dialog in which I parse the ENV and populate the combo box so that the user can select the environment we deploy to. This comboBox sets the ENV property.

I need to understand how I can use this property to copy the installed config files to the root of the site.

Update: @Rob_Mensching - your solution works, however on compilation WiX forces me to have a GUID generated for each such component. Is there a way to avoid this? The thing is, I'm going to generate this piece of code by running XSLT on my wxs file, which is generated using heat; and I cannot create a GUID using XSLT (or can I?)

This is what my code looks like:

<ComponentGroup Id='web.config' Directory='CONFIGLOCATION'>
  <Component Id='CopyWebConfigForDev1' Guid='{F207C26A-5D9C-4F19-96A3-D818BB226EFC}' >
    <Condition>ENV="Dev1"</Condition>
    <CopyFile Id='CopyDev1Config' FileId='fil9C4CFE42035F1A63180142352CF441BC' DestinationDirectory='CONFIGLOCATION' DestinationName='web.config'/>
  </Component>
  <Component Id='CopyWebConfigForQA1' Guid='{F207C26A-5D9C-4F19-96A3-D818BB226EFC}' >
    <Condition>ENV="QA1"</Condition>
    <CopyFile Id='CopyQA1Config' FileId='fil12F8B50F03F1BD91A579F6B6CE7195DF' DestinationDirectory='CONFIGLOCATION' DestinationName='web.config'/>
  </Component>
</ComponentGroup>

      

+2


source to share


2 answers


With the code Rob provided and after some research, I learned how to avoid having to provide a Guid for each component if your install folder is not a standard folder. Just specify ComponentGuidGenerationSeed for the custom directory where you are trying to install the component. The directory where you specify this attribute does not need to be the closest parent directory of where you intend to install the component. This is what my directory structure looks like:

<Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="INETPUBFOLDER" Name="inetpub">
        <Directory Id="WWWROOTFOLDER" Name="wwwroot" ComponentGuidGenerationSeed="PUT-YOUR-GUID">
          <Directory Id="CONFIGLOCATION" Name="$(var.PublishLocation)" />
          <Directory Id="INSTALLLOCATION" Name="$(var.PublishLocation)" >
            <Directory Id="APPFOLDER" Name="bin" />
            <Directory Id="MyProject.Web.Content" />
            <Directory Id="CONFIGSFOLDER" Name="Configs">
              <Directory Id="WEBFOLDER" Name="Web">
                <Directory Id="WEBCONFIGFILES" />
              </Directory>
              <Directory Id="NLOGFOLDER" Name="NLog">
                <Directory Id="NLOGCONFIGFILES" />
              </Directory>
            </Directory>
          </Directory>
        </Directory>
      </Directory>
    </Directory>

      

This is how my assembled and converted xml wxs file looks like:



<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="WEBCONFIGFILES">
            <Component Id="cmp9CAF0D4A0C62775945002986D1D99926" Guid="PUT-YOUR-GUID">
                <File Id="fil9C4CFE42035F1A63180142352CF441BC" KeyPath="yes" Source="$(var.WebConfigFilesDir)\Web.Dev1.config" />
            </Component>
            <Component Id="cmpB5117E2029EA9A7CC3AFC247EA4483AD" Guid="PUT-YOUR-GUID">
                <File Id="fil0F80FEAFAD0333C3B74BB742C4FE118C" KeyPath="yes" Source="$(var.WebConfigFilesDir)\Web.Prod.config" />
            </Component>
            <Component Id="cmp340743041F12BBE6C7C40D4351407D08" Guid="PUT-YOUR-GUID">
                <File Id="fil12F8B50F03F1BD91A579F6B6CE7195DF" KeyPath="yes" Source="$(var.WebConfigFilesDir)\Web.QA1.config" />
            </Component>
        </DirectoryRef>
    </Fragment>
    <Fragment>
        <ComponentGroup Id="WebConfigFiles">
            <ComponentRef Id="cmp9CAF0D4A0C62775945002986D1D99926" />
            <ComponentRef Id="cmpB5117E2029EA9A7CC3AFC247EA4483AD" />
            <ComponentRef Id="cmp340743041F12BBE6C7C40D4351407D08" />
        </ComponentGroup>
    </Fragment>
    <Fragment>
        <UI Id="EnvironmentComboBox">
            <ComboBox Property="ENV">
                <ListItem Value="Dev1" Text="Dev1" />
                <ListItem Value="Prod" Text="Prod" />
                <ListItem Value="QA1" Text="QA1" />
            </ComboBox>
        </UI>
    </Fragment>
    <Fragment>
        <ComponentGroup Id="web.config" Directory="CONFIGLOCATION">
            <Component Id="cmpWebConfigForDev1">
                <Condition>ENV="Dev1"</Condition>
                <File Id="CopyDev1Config" Source="$(var.WebConfigFilesDir)\Web.Dev1.config" Name="web.config" />
            </Component>
            <Component Id="cmpWebConfigForProd">
                <Condition>ENV="Prod"</Condition>
                <File Id="CopyProdConfig" Source="$(var.WebConfigFilesDir)\Web.Prod.config" Name="web.config" />
            </Component>
            <Component Id="cmpWebConfigForQA1">
                <Condition>ENV="QA1"</Condition>
                <File Id="CopyQA1Config" Source="$(var.WebConfigFilesDir)\Web.QA1.config" Name="web.config" />
            </Component>
        </ComponentGroup>
    </Fragment>
</Wix>

      

In the above file, the harvest tool only generates the first two snippets. The next two snippets, which contain the UI / ComboBox and ComponentGroup definition for WebconfigFiles, are created using XML transformation by reading information from the File elements in the first snippet.

+2


source


I would use "Component Condition" b for this. Something like the following should work well:

<Fragment>
  <ComponentGroup Id='web.config' Directory='ConfigFolder'>
    <Component>
      <Condition>ENV~="Production"</Condition>
      <File Source='web.Production.config'>
         <CopyFile DestinationDirectory='INSTALLFOLDER' DestinationName='web.config' />
      </File>
    </Component>

    <Component>
      <Condition>ENV~="Test"</Condition>
      <File Source='web.Test.config'>
         <CopyFile DestinationDirectory='INSTALLFOLDER' DestinationName='web.config' />
      </File>
    </Component>
  </ComponentGroup>
</Fragment>

      



The syntax of the conditions is documented here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa368012(v=vs.85).aspx

+2


source







All Articles