带有附加 .zip 文件的 WPF 部署

发布于 2024-10-03 09:05:14 字数 240 浏览 0 评论 0原文

我在部署独立的 WPF 应用程序时遇到问题。我有一个巨大的 .zip 文件,其中包含 pdf 文件,我想将其包含在部署中。有没有办法可以将它们添加到单击一次部署中,并让安装程序将文件解压缩到用户计算机上的特定目录中?

所以基本上,我正在寻找的是:

用户安装 WPF 应用程序 WPF 安装程序将 pdf 解压到 C:/SomeDirectory/PDFS WPF 应用程序现在可以使用这些 PDF 作为其资源。

谢谢!

I am facing a problem deploying a stand alone WPF application. I have a huge .zip file of pdf files that I want to include in the deployment. Is there a way I can add these to a click once deployment and have the installer unzip the files into a specific directory on the user's machine?

So basically, what I'm looking for is:

User installs WPF application
WPF installer unzips pdfs into C:/SomeDirectory/PDFS
WPF application can now use these PDFS as it's resource.

Thanks!

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

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

发布评论

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

评论(1

谁人与我共长歌 2024-10-10 09:05:14

根据设计,ClickOnce 不允许您在安装过程中执行任意步骤。但只要获得必要的权限,ClickOnce 应用程序首次运行时可以执行的操作就没有限制。

最常见的解决方案是在应用程序启动时检查大 zip 文件是否已解压缩,如果没有,则将 PDF 解压缩到目录中。这可以通过 SharpZipLib 或任何其他方式来完成。

另一种解决方案是使用非 ClickOnce 引导程序可执行文件来解压缩文件并执行 ClickOnce 安装。

有关 ClickOnce 不允许的原因的说明,请参阅本文自定义安装步骤,以及有关如何解决该问题的更多详细信息。

如果您同意将 PDF 放在 ClickOnce 应用程序目录中,则第三个选项是将它们包含在 ClickOnce 部署本身中。这样做的缺点是压缩会松散(除非您通过 HTTP 进行部署,服务器可能会压缩文件)。

如果您的应用程序在内部使用 PDF 文件,另一个解决方案是将大型 .zip 文件包含在清单中,在需要时解压缩各个 PDF。例如,可以使用 SharpZipLib 解压缩它们,并使用 File.WriteAllBytes(Path.GetTempFileName() + ".pdf", ...) 写出它们,或者直接加载到使用它们的任何组件中。如果您写入临时目录,您将需要一种机制来清理不再使用的文件。

最后两个解决方案中的任何一个都比将 PDF 复制到固定路径更干净,因为 ClickOnce 应用程序将是独立的并且将完全卸载。

By design ClickOnce doesn't allow you to execute arbitrary steps during installation. But given the necessary permissions there are no restrictions on what a ClickOnce application can do the first time it runs.

The most common solution is to check at application startup to see if the large zip file has been unzipped, and if not it unzips the PDFs into the directory. This can be done with SharpZipLib or any other way.

An alternative solution is to use a non-ClickOnce bootstrapper executable that unzips the files and also executes the ClickOnce install.

See this article for an explanation of why ClickOnce doesn't allow custom installation steps, and some more details on how to work around it.

If you're ok with the PDFs being inside the ClickOnce application directory, a third option is to just include them in the ClickOnce deployment itself. The disadvantage of this is that you loose compression (except that a server may compress the files if you are deploying over HTTP).

If your application uses the PDF files internally, another solution is to include the large .zip file in the manifest, unzipping individual PDFs the moment they are needed. For example, they can be unzipped using SharpZipLib and written out using File.WriteAllBytes(Path.GetTempFileName() + ".pdf", ...) or loaded directly into whatever component uses them. If you write to the temp directory you'll want a mechanism to clean up files you are no longer using.

Either of these last two solutions would be cleaner than copying the PDFs to a fixed path, because the ClickOnce application will be self-contained and will uninstall completely.

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