4
votes

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?

1
The idea is to have a nuget package that references another nuget package. Let nuget resolve references rather than you trying to outsmart it.Wiktor Zychla
You are going to have to get that ILMerge command going. There are not enough breadcrumbs but do beware that you are doing it dangerously wrong.Hans Passant
Why are you merging the DLLs into one DLL. Just merge them into the executable. I think ILMerge expects the out to be a exe, not a DLL.Also remove the double backslash in the paths, its finicky and does not do good exception handling. For instance the current version of ILMerge will throw the same error if you give it paths that have spaces in them. (btw, I merge the very same tamir.sharpSS.dll in my executable and ILMerge works flawlessly. But I merge it into the executable (.exe) not another DLL.Hashman
My goal was to make a dll and share it with other developers. That way, they can use it natively, but they cannot use an executable in their code natively.max

1 Answers

7
votes

You have several options:

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?)