是否可以创建一个自解压存档,在解压缩时运行特定文件?

时间:2012-07-10 07:46:54

标签: dotnetzip

例如,我想将包含setup.exe的应用程序部署到自解压存档中。当用户执行自解压存档时,它会将内容解压缩到临时文件夹并运行setup.exe。

这可能吗?如果是这样,有什么例子吗?

1 个答案:

答案 0 :(得分:2)

是的,这是你可以用DotNetZip做的事情之一。

文档页面提供了一个示例 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);
}