See the question and my original answer on StackOverflow

This is what's CSC (the C# compiler) calls a "link resource". It works with any type of file.

So for example, if you have this kind of code in a DLL project:

using System.Runtime.InteropServices;

namespace Microsoft.Z3
{
    public static class DoSomething
    {
        [DllImport("libz3.dll")]
        public static extern int ReturnValue(int value);
    }
}

And this C code exported from a Windows DLL:

#include "stdafx.h"

STDAPI ReturnValue(HRESULT value)
{
    return value;
}

you can build the .NET DLL like this:

"<path to csc.exe>\csc.exe" DoSomething.cs -out:Microsoft.Z3.dll -target:library -linkresource:<path to libz3.dll>\libz3.dll

Now, when you reference this new Microsoft.Z3.dll, it will behave the same way as the real Z3 thing, it will copy the libz3.dll aside automatically.

Note AFAIK, Visual Studio has no support for this linkresource stuff.

Plus one other drawback is if you want to support multiple bitnesses, you'll have to ship two .NET DLL, one for x64 and one for x86, each one embedding its native counterpart (or you'll have to duplicate all DllImport stuff etc.).