有像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 –