2

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

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

4

1 回答 1

2

是的,这是您可以做的事情之一DotNetZip

文档页面提供了一个示例。
SaveSelfExtractor 方法(exeToGenerate,选项)

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);
}
于 2012-07-11T06:27:08.423 回答