Poor-man’s .NET Linker = Embed Your Dlls

I had a need to create a simple .NET app, but it needed to be self contained in a single EXE. Native developers (C / C++) can easily create single EXE programs by utilizing the linker to pull the various pieces into the EXE. Not so easy for .NET.

I remembered reading about options for this in the past, and decided to take the quick & easy route. Options that I’ve heard of include:

  • Use the Mono tooling to “link” the dlls into the exe
  • Hook “type-resolution” events and locate the types in DLL embedded resources (no need to put dlls on disk)
  • Use embedded DLLs and simply copy them to the current directory on startup

Quick and easy for me is the last option. I embedded the DLL in the EXE and then extracted it to the file system on app startup.

One catch…

NET’s type resolution seems to work on a class by class basis. .NET wants to resolve all dependencies of the class, even if you have not yet instantiated the referenced type. So… Move the logic that uses the referenced type into a separate class. Make sure to extract dlls from the EXE before creating an instance of that class and you should be good to go.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: