开发者

Unzipping on the fly in C#

I have bu开发者_如何学编程ilt a console application that works okay when it references a .exe file from a Program Files, but my users may not have that .exe in their Program Files directory.

I would prefer to keep the package as a single .exe for simplicity, so I was wondering how I can combine the two .exe's into one package.

One thing I thought of is zipping the .exe from the Program Files directory to a temporary location, and I would store the binary data for the zip archive in my console applications source code. Is this the best way to do it or are there better methods?

Note I do not have the source code of the .exe I want to reference in my console application.


You can certainly store extra files in your .exe (or .dll) as embedded resources. Simply change the "build action" for the item in the project to "Embedded Resource". You can retrieve the contents of the file (which could be compressed, if you wished) by using the following: System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("stream name")

You could extract the file onto disk to be able to reference it, or you could load it directly with one of the Assembly.Load() variants, so you wouldn't need to ever store it on disk.

Note that if you do choose to extract it and store it on disk, you'll need administrator permissions on Vista and Windows 7 (and properly administered XP) operating systems in order to save the file(s) to the Program Files directory.


You can use GZipStream to compress and decompress files in C#. For more complex compression, you can use other Zip libraries like SharpZipLib.


Take a look at this link: Embedding assemblies inside another assembly

Basically, ILMerge will do what you are asking.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜