WPF Deployment with additional .zip file
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:/SomeDirect开发者_如何学运维ory/PDFS WPF application can now use these PDFS as it's resource.
Thanks!
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.
精彩评论