Reputation: 557
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?
Upvotes: 5
Views: 4098
Reputation: 109537
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
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. :)
Upvotes: 7