Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package whole C# Console application in one file?

Is it possible to package a whole c# console application with it's applications folder/files into one executable .exe file so it dosen't need to be installed on the computer when it's going to run?

like image 460
Raskolnikoov Avatar asked Jan 30 '14 10:01

Raskolnikoov


People also ask

What are packages in C?

A package is a group of source (. c) and header files (. h) in a subdirectory centered around either a function (e.g., the BDD variable ordering package ``ord''), or a data structure (e.g., the network package ``ntk'').

Does C have a package manager?

CLibs is a package manager for C that is focused on "micro" libraries. This means all libraries you can install with CLibs are lightweight, fast, and have a small footprint in your overall projects.

What are the header files in C?

A header file is a file with extension . h which contains C function declarations and macro definitions to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that comes with your compiler.


1 Answers

If it doesn't have a lot of resource DLLs (with translated strings, in separate subfolders) then you can use ILMerge to do this for the DLL files:

http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx

ILMerge is a utility that can be used to merge multiple .NET assemblies into a single assembly.

If you have other files too, you will have to add them as resources to your program and extract them at run-time.

See here for more details on how to embed resource files and extract them at run-time:

http://support.microsoft.com/kb/319292

Briefly: After you have added an embedded resource to your project, you do this:

 var assembly = Assembly.GetExecutingAssembly();
 var stream = assembly.GetManifestResourceStream("MyNamespace.MyResourceFileName");

 // ... do something with stream, e.g. write it out to a file.

[EDIT]

You can actually do away with ILMerge altogether and have a much more robust solution.

See here for details: http://blog.nenoloje.com/2011/08/better-alternative-to-ilmerge.html

And here: http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx

The author of ILMerge says of this "As the author of ILMerge, I think this is fantastic! If I had known about this, I never would have written ILMerge"

It's written by Jeffrey Richter, who I hope most people here will have heard of. :)

like image 186
Matthew Watson Avatar answered Sep 22 '22 15:09

Matthew Watson