有像ILMerge /自定义工具等各种选项中嵌入一个DLL到另一个。这里是一个CODE的方式:
- 在解决方案B中,转到BCrypt.dll并在属性中执行
'copy local' = false
。
- 添加DLL作为解决方案的一部分。 (如果还没有)
- 将BCrypt.dll的生成操作设置为
Embedded Resource
。
- 现在在入口点/启动B溶液DLL的代码,订阅
AssemblyResolve
事件如下:
5.
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
string dllName = args.Name + ".dll";
using (var stream= Assembly.GetExecutingAssembly().GetManifestResourceStream(dllName))
{
byte[] assemblyData = new byte[stream.Length];
stream.Read(assemblyData, 0, stream.Length);
return Assembly.Load(assemblyData);
}
};
- 基本上我们所做的是嵌入式Bcrypt.dll到解决方案B的DLL中,这样当解决方案B的dll被引用时,我们也有可用的BCrypt.dll。
- 而当.NET程序集解析失败,上述事件引发任何自定义程序集加载,我们提供我们的BCrypt的地址到流程。
如果Assembly.GetExecutingAssembly()
不起作用,它可能试图在解决方案A的资源流中搜索BCrypt。
尝试
http://blogs.msdn.com/b/saurabh_singh/archive/2009/04/08/unable-to-load-dll-bcrypt-dll-the-specified-module -could-not-found-exception-from-hresult-0x8007007e.aspx –