1

Possible Duplicate:
Embedding DLLs in a compiled executable

I would like to make a stand alone program in C#, I have a referenced dll, so I can't just copy the exe from bin/release/.exe, I have to copy both the exe and and the dll.

I want users to be able to download and run the exe, not both the exe and the dll. By stand alone I mean just the exe, without an installer.

Community
  • 1
  • 1
derp_in_mouth
  • 2,003
  • 4
  • 15
  • 17

2 Answers2

3

Take a look at ILMERGE (and download):

ILMerge is a utility for merging multiple .NET assemblies into a single .NET assembly. It works on executables and DLLs alike and comes with several options for controlling the processing and format of the output. See the accompanying documentation for details.


Alternatively, look at other deployment options, such as ClickOnce:

ClickOnce is a Microsoft technology that enables the user to install and run a Windows application by clicking a link in a web page. (Such applications are known as Smart clients.) ClickOnce is a component of Microsoft .NET Framework 2.0 and later, supports deploying applications made with Windows Forms or Windows Presentation Foundation.


A third option is to create an installer - either with a setup project or a third party installer (there are many).

Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • +1 Going the ilmerge route is "just so darn simple". However, this assumes that the other DLL is also managed/CLR and not accessed through COM-interop or anything fancy. –  Sep 01 '12 at 20:54
  • @pst - Fair point, though I think it a fair assumption. – Oded Sep 01 '12 at 20:56
  • I do to. Just adding a disclaimer :) Although the documentation does say "merge [..] .NET assemblies into [..] .NET assembly". –  Sep 01 '12 at 20:58
3

Embed your dll as a resource to your executable,

attach to AppDomain.CurrentDomain.AssemblyResolve event,

And read your dll from resource and return it, in the event.

L.B
  • 114,136
  • 19
  • 178
  • 224
  • 1
    This is the way I would go with. Recommended reading (including comments): http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx – alexn Sep 01 '12 at 20:53