0
votes

So I have a deployment project based on WIX. I notice that you can include features and files in there. However I only want to deploy a particular file if the DEV/QA environment is selected. If they select Production I want it to ignore this particular file.

Is there a way in the .wxi file to conditionally include a feature / directory & files based on a particular value of a variable?

ie. I want to have something like the below - potentially the componentRef included dynamically? (I have sanitised the values).

<Feature Id="MyApplication" Title="MyApp" Description="My Application" ConfigurableDirectory="MYAPP" Level="1">
      <ComponentRef Id="AppEmailTemplatesDir" />
 </Feature>

and then further down

<Directory Id="EmailTemplatesDir" Name="EmailTemplates">
    <Component Id="AppEmailTemplatesDir" Guid="{A-GUID}">
         <File Id="EmailTemplate1.htm" Name="EmailTemplate1.htm" DiskId="1" Source="..\..\EmailTemplates\EmailTemplate1.htm" />
    </Component>
</Directory>

Any ideas? We do have custom Actions code (VB.NET) but I'm not sure how that could be used apart from writing code to include files.

2
Do you need to conditionally include the files in the output package? Or, include ALL the files, but then conditionally install some of those? The answer depends on thisYan Sklyarenko
When I install - if the user selects QA or DEV as the environment I want to include the files in the installation. If they select PRODUCTION then I don't want to include the files (ie. I don't want to overwrite any files that are currently there on production). So I'm not trying to exclude individual files - I either want all the files or I don't want any based on the environment. Hope that helps clarify :)Jen

2 Answers

1
votes

There seem to be a variety of ways to do this ... this is what worked for me in Visual Studio 2013.

  1. In the WiX project Properties / Tool Settings add this to Additional parameters / Compiler::

    -dReleaseType=$(ReleaseType)
    
  2. Create a component group containing only the additional file (this is left as an exercise for the reader)

  3. In the main .wxs file add something like this where PDBFile is the id of the component group in step 2:

    <!-- Installs a PDB file for daily builds -->
    <?if $(var.ReleaseType) = daily ?>
      <ComponentGroupRef Id="PDBFile"/>
    <?endif?>
    
  4. Run devenv to build the WiX project with ReleaseType set in the environment

0
votes

Looks like I can use a Component NeverOverwriteOption="yes" option to ensure the installer doesn't overwrite the files when they exists.

Unless the environment conditional stuff was easy to figure out - this seems to achieve what I need which is to not overwrite the file on production.

I also found that on uninstall it was deleting all the folders (as expected) but to keep the template path I could use the Permanent="yes" attribute.

After discussion we've decided to keep all the files in source control and deploy them. But at least I learnt about NeverOverwriteOption and Permanent :)