.NET merge class library references

偶尔善良 提交于 2019-12-12 18:30:18

问题


I have a class library which contains WPF user control. This library has some dependencies but I want to deploy it as one assembly. As I know IlMerge has some problems with WPF. I tried Costura but it works only for applications, not for class libraries (as I have found out here). Is there any way to achieve my goal?


回答1:


As one of the contributors to Costura I can now confirm that it works for libraries as well as applications.

In fact all the unit tests for Costura are on a library, so it definitely works.




回答2:


Check out this link. As I read somewhere, even the author of ILMerge tells that if he knew that way, ILMerge wouldn't exist. Personally I've used it in WinForms project and it worked great, though it's stated that it handles WPF correctly.




回答3:


I know it is already answered, but to fix the loading of assemblies using reflection you can attach the following code in the AssemblyLoad event

var assembly = Assembly.LoadFile(@"<path to your dll>");
var assemblyLoaderType = assembly.GetType("Costura.AssemblyLoader", false);
var attachMethod = assemblyLoaderType?.GetMethod("Attach", BindingFlags.Static | BindingFlags.Public);
attachMethod?.Invoke(null, new object[] { });


来源:https://stackoverflow.com/questions/10959893/net-merge-class-library-references

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!