如何从 MSI 自定义操作中删除应用程序的独立存储文件和数据?

发布于 2024-12-26 11:56:54 字数 583 浏览 1 评论 0原文

我有一个 .NET 4.0 应用程序,它使用独立存储来存储我的应用程序的用户文件。最终使用如下的文件夹结构:

%LocalAppData%\IsolatedStorage\af34odgf.fj1\bheukjsx.mvr\Url.vc242bhqlc4nzx5043sp5wof15zyzvq0\AssemFiles。

我想这很好。但是,由于这些目录和文件是在安装我的应用程序后创建的,因此 Windows Installer 不会删除它们。网上有许多参考资料表明应该使用自定义操作来删除安装后创建的文件和目录。我不知道如何为IsolatedStorage 实际实现这一点。具体来说,如何从自定义操作的上下文中获取应用程序的独立存储文件夹的路径?

如果我从自定义操作中执行类似 IsolatedStorageFile.GetUserStoreForApplication(); 的操作,“应用程序”是否会引用我的安装程序而不是我的应用程序?如果是这样,这将为我提供一个完全不同的新独立存储文件夹路径。或者我对自定义操作 DLL“存在”的位置有误解吗?

我目前正在使用 WiX,但我怀疑答案可能与此无关。

I have a .NET 4.0 application that uses Isolated Storage to store user files for my application. This ends up using a folder structure like the following:

%LocalAppData%\IsolatedStorage\af34odgf.fj1\bheukjsx.mvr\Url.vc242bhqlc4nzx5043sp5wof15zyzvq0\AssemFiles.

This is fine, I think. However, since these directories and files are created after my application is installed, Windows Installer will not remove them. There are many references online that indicate that one should use a custom action to remove files and directories that are created after installation. I am stuck on how to actually implement this for IsolatedStorage. Specifically, how do I obtain the path to the Isolated Storage folder of my application from the context of the custom action?

If I execute something like IsolatedStorageFile.GetUserStoreForApplication(); from my custom action, won't "application" refer to my installer rather than my application? If so, that would give me a completely different and new Isolated Storage folder path. Or do I have a misconception about where the custom action DLLs "live"?

I am currently using WiX, but I suspect the answer is likely independent of that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

牵强ㄟ 2025-01-02 11:56:54

如果您可以让应用程序将这些文件和文件夹存储在众所周知的位置,那么您可以使用该路径设置一个属性,然后在“RemoveFolder”标记中使用它来删除卸载时的所有文件。

<RemoveFolder Id="RemoveFolder" On="uninstall" Property="TEMPLOCATION"/>

If you can get your application to store these files and folders in a well-known location then you can set a property with that path and then use it in RemoveFolder tag to remove all the files on uninstall.

<RemoveFolder Id="RemoveFolder" On="uninstall" Property="TEMPLOCATION"/>
请恋爱 2025-01-02 11:56:54

我认为解决此问题的最佳方法是让应用程序仅在注册表中保存隔离存储路径,而不是尝试维护应用程序的隔离存储代码创建或删除的每个文件的路径列表。

卸载时,可以通过名为 RemoveFolderEx。此扩展与RemoveFolder 的不同之处在于RemoveFolderEx 将删除文件夹及其内容。

另外,请参阅此相关问题/答案,IsolatedStorage:删除卸载程序中的首选项?,这表明人们可能能够移动将独立存储代码合并到主应用程序和安装程序之间共享的单独程序集中,从而允许它们引用相同的独立存储存储。

I think the best way to address this is to have the application save just the Isolated Storage path in the registry, rather than attempting to maintain a path list of every file that the Isolated Storage code for the application ever creates or deletes.

When uninstalling, this registry entry can be read and used with a WiX utils extension called RemoveFolderEx. This extension differs from RemoveFolder in that RemoveFolderEx will remove a folder and its contents.

Also, see this related question/answer, IsolatedStorage: Delete preferences in uninstaller?, which suggests that one might be able to move the Isolated Storage code into a separate assembly that is shared between the main application and the installer, allowing them to reference the same Isolated Storage stores.

独守阴晴ぅ圆缺 2025-01-02 11:56:54
[STAThread]
static void Main()
{
    //uninstall the application logic
    var args = Environment.GetCommandLineArgs();

    if(args.Any(x => string.Equals(x, "uninstall", StringComparison.OrdinalIgnoreCase))
    {
         // Your code to remove isolated storage files
         return;
    }

    // Normal Application Startup flow

}                

这可能是非常规的,但在我的应用程序中,我添加了代码,它对我有用...然后在 Wix 中添加一个安静的自定义操作 http://wixtoolset.org/documentation/manual/v3/customactions/qtexec.html 以及程序的路径,并传递卸载参数以在文件在正常卸载流程中被删除

[STAThread]
static void Main()
{
    //uninstall the application logic
    var args = Environment.GetCommandLineArgs();

    if(args.Any(x => string.Equals(x, "uninstall", StringComparison.OrdinalIgnoreCase))
    {
         // Your code to remove isolated storage files
         return;
    }

    // Normal Application Startup flow

}                

This may be unconventional, but in my applications I add code and it works for me...then in Wix add a Quiet Custom Action http://wixtoolset.org/documentation/manual/v3/customactions/qtexec.html with the path to your program and pass the uninstall argument to execute before the files are removed in the normal uninstallation flow

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文