Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to merge dll's into one dll

Tags:

c#

dll

Using c# in visual studio 2012, I've created a class library FileTube.dll It uses 3 other dll's. I want to make a single dll to contain those thus I can publish my library via nuget. I have tried 3 approaches all failing:

approach 1: In vistual studio, I set the "Embed Interop Assembly" to true, I get this error:

Error   2   Cannot embed interop types from assembly 'DiffieHellman.dll' because it is missing the 'GuidAttribute' attribute    DiffieHellman.dll

approach 2: I used ILMergeGUI. It generated the code to use for ILMerge which fails with the error: Object reference not set to an instance of an object. Here is the command:

"C:\Program Files (x86)\Microsoft\ILMerge\ILMerge.exe"
/ndebug
/copyattrs
/targetplatform:4.0,"C:\Windows\Microsoft.NET\Framework64\v4.0.30319"
/out:"C:\temp\z.dll"
"C:\\FileTube\TestApp\bin\Debug\FileTube.dll"
"C:\\FileTube\TestApp\bin\Debug\DiffieHellman.dll"
"C:\\FileTube\TestApp\bin\Debug\Org.Mentalis.Security.dll"
"C:\\FileTube\TestApp\bin\Debug\Tamir.SharpSSH.dll"

approach 3: I followed this tutorial to use reflection to include the dll assemblies. The difference is that the tutorial has a main executable and is including dll in the executable while I'm trying to include dlls in my dll. so I added the reflection code to the class constructor of my main dll. It compiles but it would fail if I rename that external dll meaning that it's not really loading it.

Any ideas?

like image 828
max Avatar asked Feb 10 '23 17:02

max


1 Answers

You have several options:

  • use ILMerge (free)
    For howto see here and here

OR

  • use some tool like SmartAssembly (commercial)
    it can embed and merge among other things (no need to change your source code)

OR

  • code that yourself in less than 10 lines (free but minimal source code change)
    mark all needed dependencies as "embedded resource" - this way they are included in the EXE file... you need to setup an AssemblyResolve handler which at runtime reads from Resources and returns the needed DLLs to the .NET runtime...

(Answer copied from: How to merge multiple assemblies into one?)

like image 77
Martin Mulder Avatar answered Feb 22 '23 22:02

Martin Mulder