卸载时如何通过Wix删除生成的文件夹和文件?
安装后,我在文件夹 C:\Program Files(x86)
中具有以下文件夹结构:
After an installation, I have the following folder structure in the folder C:\Program Files (x86)
:
生成的文件夹
的路径为: C:\程序文件(x86)\CompanyName\AppName\生成
The Path to the folder generated
is: C:\Program Files (x86)\CompanyName\AppName\generated
文件夹生成的
包含子文件夹和文件,这些文件将由应用程序在运行时通过C#代码创建:
The folder generated
contains subfolders and files they will be created by the application during the runtime via C# code:
var lPathToDir = Path.Combine(lFileService.GetFilePath, pSamAccountName);
if (!Directory.Exists(lPathToDir))
{
Directory.CreateDirectory(lPathToDir);
}
变量 lPathToDir
可能具有以下值:
C:\Program Files (x86)\CompanyName\AppName\generated\user1
// or
C:\Program Files (x86)\CompanyName\AppName\generated\user2
然后看起来像:
我的问题::卸载后,这些子文件夹 user1
, user2
将不会被删除。我使用以下Wix声明:
My Problem: After an uninstall, these subfolders user1
, user2
will not be removed. I use the following Wix declaration:
<!-- Target installation folder -->
<Directory Id="ProgramFilesFolder" Name="$(var.ProgramFilesFolder)">
<Directory Id="APPLICATIONFOLDER" Name="$(var.AppFolderName)">
<Directory Id="BIN" Name="bin" />
<Directory Id="HELP" Name="help" />
<Directory Id="GENERATED" Name="generated" />
<Component Id="RemoveAll" Guid="THE-GUID-HERE">
<RemoveFile Id="RemoveAllFilesOnUninstall" Directory="APPLICATIONFOLDER" Name="*.*" On="uninstall" />
<RemoveFolder Id="RemoveAllFoldersOnUninstall" Directory="APPLICATIONFOLDER" On="uninstall" />
<util:RemoveFolderEx On="uninstall" Property="GENERATED" />
</Component>
</Directory>
</Directory>
卸载后:
为什么保留这些文件夹,以及如何从安装文件夹中删除这些生成的文件夹?
Why do these folders stay and how can I remove these generated folders from the installation folder? Perhaps do I need to set any permissions when I create these folders via C#?
现在可以与一起使用,也许当我通过C#创建这些文件夹时需要设置任何权限吗?由Bob Arnson建议删除RemoveFolderEx
。但是除了声明< util:RemoveFolderEx On = uninstall Property = APPLICATIONFOLDER />
之外,还需要一些注册表声明:
Works now with RemoveFolderEx
as suggested by Bob Arnson. But in addition to the declaration <util:RemoveFolderEx On="uninstall" Property="APPLICATIONFOLDER" />
there are also some registry declarations necessary:
<!-- add this: -->
<Property Id="APPLICATIONFOLDER">
<RegistrySearch Key="SOFTWARE\$(var.Manufacturer)\$(var.AppName)" Root="HKLM" Type="raw" Id="APPLICATIONFOLDER_REGSEARCH" Name="Path" />
</Property>
<Directory Id="BIN" Name="bin" />
<Directory Id="HELP" Name="help" />
<Directory Id="GENERATED" Name="generated" />
<Component Id="RemoveAll" Guid="THE-GUID-HERE">
<RemoveFile Id="RemoveAllFilesOnUninstall" Directory="APPLICATIONFOLDER" Name="*.*" On="uninstall" />
<RemoveFolder Id="RemoveAllFoldersOnUninstall" Directory="APPLICATIONFOLDER" On="uninstall" />
<!-- add this: -->
<RegistryValue Root="HKLM" Key="SOFTWARE\$(var.Manufacturer)\$(var.AppName)" Name="Path" Type="string" Value="[APPLICATIONFOLDER]" KeyPath="yes" />
<util:RemoveFolderEx On="uninstall" Property="APPLICATIONFOLDER" />
</Component>
</Directory>