Is it possible to create a self-extracting archive

2019-07-19 07:36发布

问题:

For example, I want to put a deployment of an application which includes setup.exe into a self-extracting archive. When the user executes the self-extracting archive it'll unzip the contents to a temp folder and run setup.exe.

Is this possible? If so, any examples?

回答1:

yes, that's one of the things you can do with DotNetZip.

The doc page provides an example.
SaveSelfExtractor Method (exeToGenerate, options)

string DirectoryPath = "c:\\Documents\\Project7";
using (ZipFile zip = new ZipFile())
{
    zip.AddDirectory(DirectoryPath, System.IO.Path.GetFileName(DirectoryPath));
    zip.Comment = "This will be embedded into a self-extracting WinForms-based exe";
    var options = new SelfExtractorSaveOptions
    {
      Flavor = SelfExtractorFlavor.WinFormsApplication,
      DefaultExtractDirectory = "%USERPROFILE%\\ExtractHere",
      PostExtractCommandLine = ExeToRunAfterExtract,
      SfxExeWindowTitle = "My Custom Window Title",
      RemoveUnpackedFilesAfterExecute = true
    };
    zip.SaveSelfExtractor("archive.exe", options);
}


标签: dotnetzip