Add the ZIP file to the program funding source file and decompress the file at run time.
Today, I am doing research on the installation package program. My colleagues previously published a lot of scattered files into an installation folder for users. This is a poor experience. I hope to package all the files into one..
Solution Process:
1. Use the WinRAR tool to package all scattered files into a ZIP file, such as SetupRes.zip.
2. Create a console or WinForms program project as a "package project ";
3. Place the setupres.zip file under the root directory of the package project, and select this file. properties-embedded resources;
4. Add the following code:
Class Program {static void Main (string [] args) {// extract the sample string currNamespace = "leleapp1"; string fileName = "SetupRes.zip"; string resourceName = string. format ("{0 }. {1} ", currNamespace, fileName); Stream so = Assembly. getEntryAssembly (). getManifestResourceStream (resourceName); if (so! = Null) {WriteStreamFile (fileName, so); System. IO. Compression. ZipFile. ExtractToDirectory (fileName, ". \"); Console. WriteLine ("file decompressed successfully! ");} Console. read ();} private static void WriteStreamFile (string fileName, Stream stream) {FileStream fs = File. openWrite (fileName); int bytesRead = 0; byte [] buffer = new byte [65536]; while (bytesRead = stream. read (buffer, 0, buffer. length)> 0) {fs. write (buffer, 0, bytesRead);} stream. close (); fs. close ();}}
5. Compile, run, and find that the running directory has been extracted from the ZIP file and the decompressed directory.
In the future, it will be convenient to install the. NET program!