Statically link COM DLL in C# (avoid regfree)

386 views Asked by At

I have perhaps a silly question:

We have a VC++ COM DLL (developed internally) and we have ported our main app to C# and used COM Interop, reg-free to access the COM dll. Everything works just fine with internal embedded manifest.

However, the friendly product-dev/marketing/sales want to minimize the package and include the COM dll directly. Somehow, someone became convinced that the app distro should include the exe only (since it's unmanaged we can't just ILMerge it in).

Since we have the tlb/lib of the COM, could we somehow statically link it, without porting the whole COM to C# managed re-work?

Thank you

P.S. Pardon my wording: the company was downsized and I am the Python guy who had to learn everything .NET in the last week or so since now I am doing my job and the job of 2 ex-senior .net developers

2

There are 2 answers

0
StayOnTarget On BEST ANSWER

It looks like Costura can more or less do this. https://github.com/Fody/Costura

It specifically has support for merging unmanaged assemblies (ie a C++ DLL) into a .NET assembly.

Note - this is not true static linking but would achieve the aim of packaging everything in the single EXE to be distributed.

2
Joel Lucsy On

It is possible to include the source for the COM DLL into the project for the exe, or you could change the COM DLL project into a static lib project. Once you've accomplished that, you must modify the code to create the COM objects directly. All said, neither options are particularly easy.

Alternatively you could look into products like Spoon Studio that would allow you to wrap your exe and COM DLL into one exe without any code.