Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To do this, I simply created a custom action to be called on uninstall.</p> <p>The WiX code will look like this: </p> <pre><code>&lt;Binary Id="InstallUtil" src="InstallUtilLib.dll" /&gt; &lt;CustomAction Id="DIRCA_TARGETDIR" Return="check" Execute="firstSequence" Property="TARGETDIR" Value="[ProgramFilesFolder][Manufacturer]\[ProductName]" /&gt; &lt;CustomAction Id="Uninstall" BinaryKey="InstallUtil" DllEntry="ManagedInstall" Execute="deferred" /&gt; &lt;CustomAction Id="UninstallSetProp" Property="Uninstall" Value="/installtype=notransaction /action=uninstall /LogFile= /targetDir=&amp;quot;[TARGETDIR]\Bin&amp;quot; &amp;quot;[#InstallerCustomActionsDLL]&amp;quot; &amp;quot;[#InstallerCustomActionsDLLCONFIG]&amp;quot;" /&gt; &lt;Directory Id="BinFolder" Name="Bin" &gt; &lt;Component Id="InstallerCustomActions" Guid="*"&gt; &lt;File Id="InstallerCustomActionsDLL" Name="SetupCA.dll" LongName="InstallerCustomActions.dll" src="InstallerCustomActions.dll" Vital="yes" KeyPath="yes" DiskId="1" Compressed="no" /&gt; &lt;File Id="InstallerCustomActionsDLLCONFIG" Name="SetupCA.con" LongName="InstallerCustomActions.dll.Config" src="InstallerCustomActions.dll.Config" Vital="yes" DiskId="1" /&gt; &lt;/Component&gt; &lt;/Directory&gt; &lt;Feature Id="Complete" Level="1" ConfigurableDirectory="TARGETDIR"&gt; &lt;ComponentRef Id="InstallerCustomActions" /&gt; &lt;/Feature&gt; &lt;InstallExecuteSequence&gt; &lt;Custom Action="UninstallSetProp" After="MsiUnpublishAssemblies"&gt;$InstallerCustomActions=2&lt;/Custom&gt; &lt;Custom Action="Uninstall" After="UninstallSetProp"&gt;$InstallerCustomActions=2&lt;/Custom&gt; &lt;/InstallExecuteSequence&gt; </code></pre> <p>The code for the OnBeforeUninstall method in InstallerCustomActions.DLL will look like this (in VB).</p> <pre class="lang-vb prettyprint-override"><code>Protected Overrides Sub OnBeforeUninstall(ByVal savedState As System.Collections.IDictionary) MyBase.OnBeforeUninstall(savedState) Try Dim CommonAppData As String = Me.Context.Parameters("CommonAppData") If CommonAppData.StartsWith("\") And Not CommonAppData.StartsWith("\\") Then CommonAppData = "\" + CommonAppData End If Dim targetDir As String = Me.Context.Parameters("targetDir") If targetDir.StartsWith("\") And Not targetDir.StartsWith("\\") Then targetDir = "\" + targetDir End If DeleteFile("&lt;filename.extension&gt;", targetDir) 'delete from bin directory DeleteDirectory("*.*", "&lt;DirectoryName&gt;") 'delete any extra directories created by program Catch End Try End Sub Private Sub DeleteFile(ByVal searchPattern As String, ByVal deleteDir As String) Try For Each fileName As String In Directory.GetFiles(deleteDir, searchPattern) File.Delete(fileName) Next Catch End Try End Sub Private Sub DeleteDirectory(ByVal searchPattern As String, ByVal deleteDir As String) Try For Each dirName As String In Directory.GetDirectories(deleteDir, searchPattern) Directory.Delete(dirName) Next Catch End Try End Sub </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload