tags:

views:

80

answers:

3

I have built 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.

+1  A: 

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

Yuriy Faktorovich
Yeah. I don't have a problem with compressing/decompressing, just wondering what would be the best way to store the binary data of the archive in my source code, and if it's even possible. For example I'd have a string called "programSource" that I would make a file out of, and then I'd be able to run the typical decompression methods on that archive to get the files I want out of it. Thanks.
Kratz
A: 

Take a look at this link: http://stackoverflow.com/questions/222655/embedding-assemblies-inside-another-assembly

Basically, ILMerge will do what you are asking.

Russ
+2  A: 

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.

Mark
That's exactly what I want, thanks. Would extracting to a location like `C:\tmp` need administrator priveledges? Although it isn't really a problem.Thanks. :)
Kratz
Possibly, depending on how security is set up. Your safest bet would be to use `System.IO.Path.GetTempPath()` to find the local temporary directory.
Mark