有人成功 iLMerged Enterprise Library 5.0 吗? iLMerge 成功创建了合并的 dll 并且我的 mvc 应用程序编译了,但是在启动应用程序时我收到以下错误:
SecurityTransparent and SecurityCritical attributes cannot
be applied to the assembly scope at the same time.
请您参考如下方法:
如果您编写了所有要合并的程序集,并且您知道它们都没有对程序集组织做出假设,那么 ILMerge 非常有用。但在许多情况下(尤其是涉及大量反射或动态语言运行时的情况),ILMerge 根本不起作用。有时事情会以令人惊讶和神秘的方式失败。
当 ILMerge 失败时,Jeffrey Richter h a more reliable way to get applications with multiple DLL dependencies to be deployable as a single assembly .
通过他的方法,每个程序集都可以保留自己的名称、强名称和属性,这大大提高了生成的应用程序正常工作的机会。
这并非没有取舍,但即使是 ILMerge 的作者 Mike Barnett 也在该博文的评论线程中说“作为 ILMerge 的作者,我认为这太棒了!如果我早知道这一点,我永远不会写 ILMerge。”
如果你能使用里希特的方法,你就不会被大多数反射或动态陷阱绊倒。
实现步骤
- 将您依赖的所有第三方程序集嵌入到应用程序的资源中。
- 注册
ResolveEventHandler使用AppDomain.CurrentDomain.AssemblyResolve事件。 - 当您的处理程序使用您隐藏在资源中的程序集被调用时,加载该程序集。
您按如下方式执行第 3 部分:
var resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
return Assembly.Load(new BinaryReader(resourceStream).ReadBytes(int.MaxValue));
