从运行.Net应用程序一个COM pressed"拉链"文件 [英] Running a .Net application from a compressed "zip" file

查看:193
本文介绍了从运行.Net应用程序一个COM pressed"拉链"文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个可以很容易地散发出轻量级.NET应用程序(通过电子邮件的附件,例如)。我可以从一个ZIP运行EXE,但看来我不能让EXE引用任何外部配置文件(如exe.config,或任何其他的XML文件)从zip中运行时。

I need to create a lightweight .Net application which can be distributed easily (via email attachment, for example). I can run the EXE from a ZIP, however it seems I cannot get the EXE to reference any external configuration files (such as an exe.config, or any other XML file) when run from the zip.

难道不能当EXE使用的数据来自exe.config文件从一个zip文件运行EXE?

Is it not possible to run an EXE from a zip file when that EXE uses data from the exe.config file?

我已审查已经这样一个问题:

I have reviewed this question already:

<一个href="http://stackoverflow.com/questions/126611/net-windows-application-can-it-be-com$p$pssed-into-a-single-exe">.NET Windows应用程序,它可以将COM pressed成一个.exe文件?

但我想他正试图解决不同的问题,而不是我。

but I think he is trying to solve a different problem than I am.

我相信我的问题是与此类似: 裹文件在一个可执行包

I believe my problem is similar to this: Wrap files in one executable package

然而,答案这个问题提供了一个明确的解决方案。

However the answers for this question have provided a clear solution.

推荐答案

这可能吗?那么让我们来看看这里的情况。

Is it possible? Well let's look at the situation here.

一个zip文件的归档格式。它没有指定幻数;而是一个zip文件确定的标记的记录(ZIP项)$ P​​ $ psent文件中的任何地方presence。

A zip is an archive format. It does not specify a magic number; instead a zip file is identified by the presence of marked records (zip entries) present anywhere in the file.

在窗口,一个EXE是一个神奇的数字定义的文件格式。它允许对包含任意的数据和在该文件中被特别标记的地方。

In windows, an EXE is a file format defined by a magic number. It allows for the inclusion of arbitrary data and specially-marked places in the file.

两者结合,就可以进行文件既一个exe和拉链。这种可能性是利用生产自解压文件(SFX):一个exe其中阅读本身作为一个zip文件的,并提取其中包含的条目。一个SFX基本上是由一个知道如何阅读和提取任何的zip文件,以及一组变量的ZIP条目记录了一些存根EXE逻辑。

Combining the two, it is possible for file to be both an exe and a zip. This possibility is exploited in producing self-extracting zip files (SFX): an exe which reads itself as a zip file and extracts the entries contained within. An SFX is basically comprised of some "stub" exe logic that knows how to read and extract any zip file, plus a variable set of zip entry records.

您的要求 - 即提取本身就是一种归档格式,然后运行从提取的内容一个特定的文件 - 需要一个SFX存根,这只是的稍微能够的比标准之一。它必须解压缩文件,然后运行这些文件中的一个。

Your requirement - an archive format that extracts itself, then runs a particular file from the extracted content - requires an SFX stub that is only slightly more capable than the standard one. It must extract files, then run one of those files.

DotNetZip 是一个基于.NET的拉链库,让你的.NET应用程序来生成压缩文件包括SFX文件。通过DotNetZip提供的SFX存根,包括调用提取的文件之一,提取后的能力。该命令对运行后提取不必是.NET可执行文件,但它可能是。当然,由于该exe和它的配置文件已被提取出来,这个exe可以成功运行,能够访问config文件。这应该满足您的要求。

DotNetZip is a .NET-based zip library that allows your .NET app to produce zip files, including SFX files. The SFX stub provided by DotNetZip includes the ability to invoke one of the extracted files, after extraction. The command-to-run-after-extraction need not be a .NET executable, but it could be. Of course, since the exe and its config file have been extracted, the exe can run successfully, with access to the .config file. This should meet your requirements.

在code。使用DotNetZip生产运行后提取命令看起来像这样一个SFX:

In code using DotNetZip to produce an SFX that runs a post-extract command looks like this:

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 console-based exe";
    SelfExtractorOptions options = new SelfExtractorOptions();
    options.Flavor = SelfExtractorFlavor.ConsoleApplication;
    options.DefaultExtractDirectory = "%USERPROFILE%\\ExtractHere";
    options.PostExtractCommandLine = "%USERPROFILE%\\ExtractHere\\MyApp.exe";
    options.RemoveUnpackedFilesAfterExecute = true;
    zip.SaveSelfExtractor("archive.exe", options);
}

DotNetZip是免费使用。

DotNetZip is free to use.

这篇关于从运行.Net应用程序一个COM pressed&QUOT;拉链&QUOT;文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆