简体   繁体   English

内化.NET Assembly中的类和方法

[英]Internalize Class and Methods in .NET Assembly

I have a set of multiple assemblies (one assembly is to be used as an API and it depends on other assemblies). 我有一组多个程序集(一个程序集将用作API,它取决于其他程序集)。 I would like to merge all assemblies into one single assembly but prevent all assemblies except the API one to be visible from the outside. 我想将所有程序集合并为一个程序集,但要防止从外部可见除API之外的所有程序集。

I will then obfuscate this assembly with Xenocode. 然后,我将使用Xenocode混淆此程序集。 From what I have seen, it is impossible to internalize assembly with Xenocode. 从我所看到的,用Xenocode内部化程序集是不可能的。

I have seen ILMerge from Microsoft, but was unable to figure if it can do what I want. 我已经从Microsoft看过ILMerge,但是无法确定它是否可以满足我的要求。 http://research.microsoft.com/~mbarnett/ILMerge.aspx http://research.microsoft.com/~mbarnett/ILMerge.aspx

I have used ILMerge from microsoft to internalize DLL's into a single assembled library. 我已经使用了Microsoft的ILMerge将DLL内部化为一个组装的库。 There is a useful GUI for using ILMerge called NuGenUnify. 有一个使用ILMerge的有用GUI,称为NuGenUnify。 You can find it here . 你可以在这里找到它。

I suggest you look at the InternalsVisibleTo attribute on MSDN . 建议您查看MSDN上的InternalsVisibleTo属性。

You can mark everything in all the assemblies (except the API assembly) as internal instead of public , then reshow them to just your API assembly. 您可以将所有程序集(API程序集除外)中的所有内容标记为internal而不是public ,然后将它们重新显示为您的API程序集。

Having done that, using ILMerge should give you a single assembly with just the API classes visible. 完成此操作后,使用ILMerge应该会为您提供一个仅具有可见API类的程序集。

There are some issues with ILMerge , but I think if you add optimisations + merge + obfuscation you're likely to create a highly complex situation for little benefit. ILMerge存在一些问题 ,但是我认为,如果添加优化+合并+模糊处理,很可能会创建一个非常复杂的情况,而带来的好处却很少。

Why not have just one assembly, and make only your API public? 为什么不只有一个程序集,而只公开您的API?

If you're always distributing them as a single assembly there's no reason not to just compile them as that. 如果您始终将它们作为单个程序集分发,则没有理由不只是那样编译它们。 You'll get more benefit from compiler optimisations and it will be quicker to compile too. 您将从编译器优化中获得更多收益,并且编译起来也将更快。

I know Xenocode can merge assemblies into one but I am not sure if it will internalize other non-primary assemblies. 我知道Xenocode可以将程序集合并为一个,但是我不确定是否会将其他非主程序集内部化。

I have found the /internalize switch in ILMerge that "internalize" all assemblies except the primary one. 我发现ILMerge中的/ internalize开关可以“内部化”除主程序集以外的所有程序集。 Pretty useful! 非常有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM