Is it possible to create a self-extracting archive

2019-07-19 07:04发布

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?

标签: dotnetzip
1条回答
劳资没心,怎么记你
2楼-- · 2019-07-19 07:55

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);
}
查看更多
登录 后发表回答