How can I remove a folder located in the same folder of my setup after installation in Wix? - wix

I am trying to make a setup file for an application with Wix. After the installation of the program the setup should remove a folder located in its same folder. I don't know how to do it. All I know is that I have to use the RemoveFolder element, that must be placed inside a Component element. So far I have written this but it doesn't work.
<Component Directory="CURRENTDIR" Id="cd1">
<RemoveFolder Id="rf1" On="install" Directory="NameOfFolderToRemove"/>
</Component>

Take a look at util:RemoveFolderEx
http://wixtoolset.org/documentation/manual/v3/xsd/util/removefolderex.html
You will need to reference WixUtilExtension in your project and include
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
in your Wix tag like below:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<RemoveFolder> will only remove empty folders so if there are files in the folder the remove folder action won't work.

Related

DirectoryRef: use in 2 different folders

In my installer project I have a harvested output of a referenced project which creates a fragment and, inside it, DirectoryRef element.
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="MyProject.Content">
<Directory Id="dir9B0F2CD8423EA8141263E4CAA24D1234" Name="Data">
<!-- subfolders, components etc. -->
Now, in my main wxs file I need to include MyProject.Content directory as a subfolder of two different directories.
I include <Directory Id="MyProject.Content" /> as a child of one directory and it works fine, files are added.
But if I include it in another directory I get:
error LGHT0091: Duplicate symbol 'Directory:MyProject.Content' found.
How can I reuse DirectoryRef twice?
The Id of non-Ref elements must be unique. So, somewhere in your .wxs code you have Directory Id='MyProject.Content' twice.
Unfortunately, the design of heat.exe that is part of the WiX Toolset adds a lot of identifiers preventing your scenario. You'd need to remove the Id attributes and probably still have to harvest twice to get two different ComponentGroup identifiers. This scenario just isn't in the design of heat.exe.
Contrast that with something like the WiX Expansion Pack advanced harvesting's solution where the HarvestFolder or HarvestProject element is placed directly in your .wxs code. Then you can place those elements in the appropriate directories and unique identifiers will be generated.

WIX Toolset Bundle get parent directory of path returned from ComponentSearch

I am attempting to have my WIX bundle use the previous install directory if an earlier version is already installed. The previous versions did not create a registry entry for the install location. As such I tried to use a ComponentSearch (Util Extension) to find the main executable. The install directory is the parent directory of the directory containing the executable. The ComponentSearch gives me the directory C:\InstallDirectory\DirectoryContainingEXE. How can I get C:\InstallDirectory?
<?xml version="1.0" encoding="utf-8"?>
<Include xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
<Fragment>
<util:ComponentSearch Id="ExeComponentSearch" Guid="{COMPONENT GUID}" Result="directory" Variable="InstallFolder"/>
</Fragment>
</Include>
I found a solution. The obvious solution is to use a file whose parent is the C:\InstallDirectory. Since I don't have any files in the C:|InstallDirectory that would not work. What I did have is a component that sets permissions on the C:\InstallDirectory. I used that component to get the directory. This would probably work with other types of components that do not contain a file. Maybe a registry that is the key path of the component?
<util:ComponentSearch Id="InstallDirectoryPermissionsSearch" Guid="{COMPONENT GUID}" Result="directory" Variable="InstallFolder"/>

WixToolset 3.11 Util:PermissionEx error for createfolder

I am new to Wix installation toolkit and have been trying to create an installer. I am using it as a plugin to VS 2017. This is so far as I have got.
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util=" http://schemas.microsoft.com/wix/UtilExtension">
<Directory Id="CommonAppDataFolder">
<Directory Id="ProgramDataVendorFolder" Name="ABC">
<!--This will create the \ProgramData\MyVendor\MyProductName\ folder. -->
<Directory Id="ProgramDataAppFolder" Name="DEF" />
</Directory>
</Directory>
</Directory>
<DirectoryRef Id="ProgramDataAppFolder">
<Component Id="CmpCreateCommonAppDataFolderWithPermissions" Guid="*" Permanent="yes">
<CreateFolder>
<!--This will ensure that everyone gets full permissions to the folder that we create in the ProgramData folder.-->
<util:PermissionEx User="Everyone" GenericAll="yes" />
</CreateFolder>
</Component>
</DirectoryRef>
Added a reference to "WixUtilExtension.dll" in the project.
But I get the error
Error : The CreateFolder element contains an unhandled extension
element 'util:PermissionEx'. Please ensure that the extension for
elements in the ' http://schemas.microsoft.com/wix/UtilExtension'
namespace has been provided.
In addition I have also tried using the http://wixtoolset.org/schemas/v4/wxs/util instead of http://schemas.microsoft.com/wix/UtilExtension
I tried to comment out the code above and then get the error
The extension
'Microsoft.Tools.WindowsInstallerXml.Extensions.UtilExtension'
contains a defintion for table 'EventManifest' that collides with a
previously loaded table definition. Please remove one of the
conflicting extensions or rename one of the tables to avoid the
collision.
Could someone please help me out here.
Missing Reference: You must have forgotten to add a reference to the
WixUtilExtension.dll file in the WiX installation folder. Please follow the procedure below to add the reference.
In Visual Studio:
Open your WiX project.
Right click "References" in the right pane => Add References...
Browse to the file, or paste the following (if using standard installation paths)C:\Program Files (x86)\WiX Toolset v3.11\bin\WixUtilExtension.dll.
Click "Add" and then "OK".
WiX Sample Code: Some WiX sample code described here.
The most common namespaces to add to the WiX element:
xmlns:bal="http://schemas.microsoft.com/wix/BalExtension" (Burn)
xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension" (.NET)
xmlns:iis="http://schemas.microsoft.com/wix/IIsExtension" (IIS)
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension" (Util)
xmlns:wixloc="http://schemas.microsoft.com/wix/2006/localization" (Localization)
IsWiX is nice for namespaces and more (screenshot below). It is a free WiX tool from Chris Painter:
You have a leading space in the xmlns:util namespace. Remove this and things should work OK.

Wix Toolset - Variable Shared Across Projects/Solution

I am trying to share a variable across 2 of my wix projects but I am having issues.
Basically I am trying to accomplish having the version number of my bootstrapper and MSI in one file and then this referenced by the two projects.
I have three projects
Install - This is a setup project that creates an .msi file
Bootstrapper - This is a Wix Bootstrapper project that references and runs the .msi file at runtime
Shared - This is a wixlib project that contains a single variable in a fragment that is the version number
The shared project contains a single file i have called GlobalVars.wxs and looks like this
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<?define VersionNo = "6.86.123"?>
</Fragment>
</Wix>
The bootstrapper references this variable like this
<Bundle Name="ProgramName" Version="$(var.VersionNo)" Manufacturer="CompanyName" UpgradeCode="Guid" Compressed="no">
and the Install project references the variable like this - and has a reference to the .wxs from the shared project
<Product Id="*" Name="Program Name" Language="2057" Version="$(var.VersionNo)" Manufacturer="CompanyName" UpgradeCode="guid">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" InstallPrivileges="elevated"/>
<?include GlobalVars.wxs ?>
Both projects have references setup to the wixlib project that contains the variable
When i attempt to build I am getting this error on both the install and bootstrapper project
Undefined preprocessor variable '$(var.VersionNo)'.
If the <?include?> tag resolved the issue I would expect the install project to build
Does anyone have any ideas as to what I might be doing wrong here?
To me it looks like the variable has not been defined by the time the build attempts to call it, but I am unsure as to show to change the order to ensure the variable is defined before anything else
Thanks for the help
I believe the answer to this question will help. I've used it and noticed that properties seem to be usable in my main wxs file.
To summarise, you need to set up a fake componentGroup in your library fragment, and use it in your installer. You do not need the include anymore, as long as the fake componentGroup from your fragment is referenced as a componentGroupRef in your main install, and your wixlib project is referenced in your installer project through VS (you said you'd already done this in your comments above).
Your library fragment might look something like this.
<Fragment id="fragment_id_may_not_be_needed">
<?define VersionNo = "6.86.123"?>
<ComponentGroup Id="c.define_version_num" />
</Fragment>
If the define for whatever reason doesn't work, try using a property instead. I'd be interested to know which works. Properties seem to work for me.
Then reference it in your main install like this:
<Feature Id="Main_installation" Title="Main installation" Level="1">
<!-- bringing in fragments from the shared libraries -->
<ComponentGroupRef Id="c.define_version_num" />
</feature>
Give it a whirl.

WiX Relative Path to the Source File

I have a simple Solution for my Project, which works well. But I am unable to grasp how to make the Source paths relative. Can somebody help me?
<Component Id="Bla.exe" Guid="*">
<File Id="Bla.exe" Source="D:\Projects\Bla\Bla\bin\Debug\Bla.exe" KeyPath="yes" Checksum="yes"/>
</Component>
How can I make the Path relative to the Wix Solution? WiX and all necessary files are in the same Solution.
You can use the relative path like so:
<File Id="Bla.exe" Source="..\bin\Debug\Bla.exe" KeyPath="yes" Checksum="yes"/>
OR
You can add a configuration file to your project to define common variables. To do so, add a new "WiX Include" file to your project, call it config.wxi. Then in your include file, you can define a SourceDir variable like so:
<?xml version="1.0" encoding="utf-8"?>
<Include>
<?define SourceDir = "D:\Projects\Bla\Bla\bin\Debug" ?>
</Include>
Now in your .wxs file, you can add a reference to the config file at the top, ex:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<?include "config.wxi"?>
Then just reference your SourceDir variable like so:
<File Id="Bla.exe" Source="$(var.SourceDir)\Bla.exe" KeyPath="yes" Checksum="yes"/>
Also, there are some built in WiX project variables that you may use.
There are many ways to do this but personally what I like to do is put my application installer projects in different solutions. I build the application solution first and use postbuild commands to publish the content to a deploy folder.
In my installer projects I set $(var.SourceDir)="..\deploy" and then $(var.SourceDir)\foo.exe for a source path.