2

Possible Duplicate:
Embedding DLLs in a compiled executable

I have a c# winforms application along with a few depending .dlls and a dependant external .exe.

Is it possible to somehow complile all of them into one executable (not installer) just stand alone executable?

From VS 2010 Ultimate if possible?

Community
  • 1
  • 1
sd_dracula
  • 3,796
  • 28
  • 87
  • 158
  • 1
    You should *really* consider [**searching**](http://bit.ly/11dYmgf) before posting a question. You couldn't possibly think you were the first one to ever need to do this, did you? – Jonathon Reinhart Jan 09 '13 at 03:32
  • What research have you done? Sharing your research helps everyone. Tell us what you found and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer:) Good Luck! – Jeremy Thompson Jan 09 '13 at 03:33
  • I have come across ILMerge as someone already mentioned here: http://stackoverflow.com/questions/189549/embedding-dlls-in-a-compiled-executable but I'm still unsure as whether I can add EXEs/XML files to it also. – sd_dracula Jan 09 '13 at 04:21

2 Answers2

1

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

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • this is possible ONLY if dll's are managed dll's. – Yusubov Jan 09 '13 at 03:37
  • Yes - thats a given. I'm not too sure about the comment. Are you saying your method would work with unmanaged DLLs? – Jeremy Thompson Jan 09 '13 at 03:39
  • Because you will get issues while trying to load unmanaged once in ILMerge. Even if you could figure it out, the CLR might refuse to run it if it sensed that the managed code was generated in part by the un-managed dll's. – Yusubov Jan 09 '13 at 03:55
  • the more important question is what to do with the external dependent .exe mentioned in the OP... and if that assembly itself is managed or not. :) – Seph Jan 09 '13 at 04:18
1

In short: the only way that may work is to add all external files as an embedded resource and use ILMerge.

Option #1: the following steps show how to embed a resource file Inside Visual Studio :

  1. Go to Solution Explorer,
  2. Right click the resource file,
  3. GO to Build Actions: Select Embedded Resource.

You will have that file reference inside the exe. Later you can use Reflection and get the resource when you run your application. Borrowed Source Code from here:

Option #2 with managed dll's:

For the managed DLLs you have a couple of options:

  • Use ILMerge. ILMerge has a nice GUI interface that can be found [here]7]
  • Embebed them as a resource, see this article for details.

Check out the following CodeProject article that explains this .

ILMerge is a utility that can be used to merge multiple .NET assemblies into a single assembly. ILMerge takes a set of input assemblies and merges them into one target assembly. The first assembly in the list of input assemblies is the primary assembly. When the primary assembly is an executable, then the target assembly is created as an executable with the same entry point as the primary assembly. Also, if the primary assembly has a strong name, and a .snk file is provided, then the target assembly is re-signed with the specified key so that it also has a strong name.

Yusubov
  • 5,815
  • 9
  • 32
  • 69
  • Pretty sure OP wants to include code DLLs (not DLLs purely containing resources) into the single EXE. Your answer is more along the lines of satellite assemblies. – Jeremy Thompson Jan 09 '13 at 03:37
  • This really won't work. If your EXE references the DLLs, it is going to fail to load in the first place, and thus be unable to extract them. – Jonathon Reinhart Jan 09 '13 at 03:40
  • i have added the managed dll option, no problem. – Yusubov Jan 09 '13 at 03:44
  • 1
    Why do you still place emphasis on the **possible only if the dll's are managed dll's** - both methods will NOT work on unmanaged DLLs!! – Jeremy Thompson Jan 09 '13 at 03:50
  • Because you will get issues while trying to load unmanaged once in ILMerge. Even if you could figure it out, the CLR might refuse to run it if it sensed that the managed code was generated in part by the un-managed dll's. – Yusubov Jan 09 '13 at 03:55