11

I have 4 dlls. But I want to have 1 single dll which will contain the code from all 4 of these dlls. I tried to add a project and copy paste all of my existing code into one project, but I couldn't.

4
  • Add them as a resources, use Solution Explorer, open project properties, and add requred assemblies as binary resources Commented Sep 13, 2011 at 5:33
  • I was making Class Library(common dialogs).But i found some of them,but those are in class library project too.I added them as existing project to my PROJECT(class library).And when i build and want to use them i must add each one to references
    – Javidan
    Commented Sep 13, 2011 at 5:42
  • Add refereces to these DLL's to project, but in Refenced assemblies section of the project, point on them and choose in Property Editor for referenced assemblies "Copy Local: False, Embed Types: False", then just load em as usual, from embedded resource in Application section just before Application.Run() method call, where these assemblies referenced by your main assembly, Anyway, you can reference assemblies in project in design time and do not allwo copying them into assembly output folder, instead, store as a resource in one assembly load when this storage assembly referenced to Commented Sep 13, 2011 at 6:12
  • I did what you want but you couldnt understand me,i have main class which will create dilaogs(DialogFactory.ColorPicker arg=new DialogFactory.ColorPicker).When i add this dll(dialogFactory) to any windows application,i must add not only this but also other dlls which i used in DialogFActory
    – Javidan
    Commented Sep 13, 2011 at 6:23

3 Answers 3

13

Have a look into ILMerge

ILMerge is a utility for merging multiple .NET assemblies into a single .NET assembly.

9
  • @Javidan Why you do not want to just embedding your dlls as a resources in one dll? You will not need to touch assemblies, because they might be signed, and require resign the resulting assembly after merge at IL level. Commented Sep 13, 2011 at 5:31
  • I dont know what to do.i've installed ilmerge,but couldnt use.And dont know which is comfortable and safe method to combine.
    – Javidan
    Commented Sep 13, 2011 at 5:38
  • ILMerge is a utility that is run post-compile which will merge all your assemblies into a resultant assembly. Run the utility on the command line like "C:\Program Files\Microsoft\ILMerge\ILMerge.exe" /out:SampleApp1.exe SampleApp1.exe SharpSnmpLib.dll. You can also add a command like this to your post-build processing of your project. Commented Sep 13, 2011 at 5:44
  • There is nothing like ILMerge.exe.But i already installed this.
    – Javidan
    Commented Sep 13, 2011 at 5:53
  • If you are running x64, then did you check "C:\Program Files (x86)\Microsoft\ILMerge\"? Commented Sep 13, 2011 at 6:00
8

You can use ILMerge utility

Or you can embed the dlls you want to merge as resources

Here the code sample:

AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
   using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
   {
      Byte[] assemblyData = new Byte[stream.Length];
      stream.Read(assemblyData, 0, assemblyData.Length);
      return Assembly.Load(assemblyData);
   }
};
2
  • I've always had loads of problems trying to load embedded DLLs ... it's been awhile, but IIRC the problem I was having was, even with Load(byte[]) the assembly was attempted to be loaded from disk.
    – user166390
    Commented Sep 13, 2011 at 5:35
  • @pst There is no problem with loading assemblies, since you can load it in it's own application domain, and control access and versioning manually over it. And yes, assemblies while loaded in application domain, can't be reloaded from disk or rewritten by another assembly, being already loaded in-memory. It's by design. Commented Sep 13, 2011 at 5:40
3

There is a tool from MS: ILMerge

Not the answer you're looking for? Browse other questions tagged or ask your own question.