卸载WiX时删除文件卸载我的应用程序时,我想配置Wix设置以删除原始安装后添加的所有文件。看起来卸载程序只删除了最初从MSI文件安装的目录和文件,并且它保留了稍后在应用程序文件夹中添加的所有其他内容。换句话说,我想在卸载时清除目录。我怎么做?
3 回答
哈士奇WWW
TA贡献1799条经验 获得超6个赞
使用RemoveFile元素和On =“ uninstall ”。这是一个例子:
<Directory Id="CommonAppDataFolder" Name="CommonAppDataFolder"> <Directory Id="MyAppFolder" Name="My"> <Component Id="MyAppFolder" Guid="*"> <CreateFolder /> <RemoveFile Id="PurgeAppFolder" Name="*.*" On="uninstall" /> </Component> </Directory></Directory>
更新
它不起作用100%。它删除了文件,但没有删除任何其他目录 - 安装后创建的目录。有什么想法吗? - pribeiro
遗憾的是,Windows Installer不支持使用子目录删除目录。在这种情况下,您必须采取自定义操作。或者,如果您知道子文件夹是什么,请创建一堆RemoveFolder和RemoveFile元素。
神不在的星期二
TA贡献1963条经验 获得超6个赞
RemoveFolderEx
在WiX中使用Util扩展中的元素。
使用此方法,还会删除所有子目录(而不是直接使用RemoveFile
元素)。此元素在MSI数据库中添加临时行RemoveFile
和RemoveFolder
表。
HUH函数
TA贡献1836条经验 获得超4个赞
为此,我只是创建了一个在卸载时调用的自定义操作。
WiX代码如下所示:
<Binary Id="InstallUtil" src="InstallUtilLib.dll" /><CustomAction Id="DIRCA_TARGETDIR" Return="check" Execute="firstSequence" Property="TARGETDIR" Value="[ProgramFilesFolder][Manufacturer]\[ProductName]" /><CustomAction Id="Uninstall" BinaryKey="InstallUtil" DllEntry="ManagedInstall" Execute="deferred" /><CustomAction Id="UninstallSetProp" Property="Uninstall" Value="/installtype=notransaction /action=uninstall /LogFile= /targetDir="[TARGETDIR]\Bin" "[#InstallerCustomActionsDLL]" "[#InstallerCustomActionsDLLCONFIG]"" /><Directory Id="BinFolder" Name="Bin" > <Component Id="InstallerCustomActions" Guid="*"> <File Id="InstallerCustomActionsDLL" Name="SetupCA.dll" LongName="InstallerCustomActions.dll" src="InstallerCustomActions.dll" Vital="yes" KeyPath="yes" DiskId="1" Compressed="no" /> <File Id="InstallerCustomActionsDLLCONFIG" Name="SetupCA.con" LongName="InstallerCustomActions.dll.Config" src="InstallerCustomActions.dll.Config" Vital="yes" DiskId="1" /> </Component></Directory><Feature Id="Complete" Level="1" ConfigurableDirectory="TARGETDIR"> <ComponentRef Id="InstallerCustomActions" /></Feature><InstallExecuteSequence> <Custom Action="UninstallSetProp" After="MsiUnpublishAssemblies">$InstallerCustomActions=2</Custom> <Custom Action="Uninstall" After="UninstallSetProp">$InstallerCustomActions=2</Custom></InstallExecuteSequence>
InstallerCustomActions.DLL中的OnBeforeUninstall方法的代码如下所示(在VB中)。
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("<filename.extension>", targetDir) 'delete from bin directory DeleteDirectory("*.*", "<DirectoryName>") 'delete any extra directories created by program Catch End TryEnd SubPrivate 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 TryEnd SubPrivate 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 TryEnd Sub
添加回答
举报
0/150
提交
取消