tags:

views:

796

answers:

3

Is there a way to compile C# files into one single file that is ready to give to the user?

+9  A: 

One way is to use ILMerge. This will merge multiple assemblies into a single one (think combining all DLLs and a main exe into a single exe).

dpp
Do you know of any good tutorials on how to use this tool?
Lucas McCoy
A short but useful article from CodeProject: http://www.codeproject.com/KB/dotnet/mergingassemblies.aspx
dpp
+2  A: 

Yes :) But you must put all your sources into a single assembly and compile it to an EXE. Also note that the target system must also have the required .NET infrastructure installed.

Note that security policies on the target system may prevent the user from directly running your app.

Lastly, unless you "NGEN" your code, it will be jitted the first time it runs. This will incur some startup time costs. THese can be considerable in some instances.

Foredecker
The jitting that occurs should be no different than if the program were a set of assemblies - jitting occurs on a method-by-method basis when each method is first called. Presumably, methods will be called in the same sequence whether the program is packaged in a single .exe or several assemblies.
Michael Burr
@Michael - unless there was an edit, the only reference to JIT relates to NGEN; in which case, no: it *won't* be jitted on a method-by-method basis...
Marc Gravell
@Marc - I was thinking that the NGEN comment implied that combining the assemblies into a single .exe would increase the startup time over having multiple assemblies. In other words, I was trying to say that whether you want or need NGEN is likely independent of whether your assemblies are merged.
Michael Burr
+2  A: 

If your looking to also merge the .Net assemblies required by your app, you can use something like This to even compile in System.dll, System.Windows.Forms.dll, etc, so the end user wont even need .Net installed.

Neil N
That is pretty cool, I just wish I had $1500.00 to throw around.
Lucas McCoy
I guess Mono now offers a similar functionality, and Mono is free.
Neil N