简体   繁体   English

拒绝客户端代码访问.NET中的第三方库

[英]Deny client code access to a third-party library in .NET

I am writing a Library using C# and my library uses a third party .NET library. 我正在使用C#编写库,而我的库则使用第三方.NET库。 When I roll out my Library I have to include the third-party library as well along with my library. 当我推出我的图书馆时,我必须同时包括第三方图书馆和我的图书馆。 However I want to prevent users of my library (client code) from directly using the third-party library. 但是,我想防止我的库(客户端代码)的用户直接使用第三方库。 Is there any way to enforce that at compile time or run time? 有什么方法可以在编译时或运行时强制执行吗?

If there are no legal issues with doing so, you can use ILMerge to merge the 3rd party library into your own one. 如果这样做没有法律问题,则可以使用ILMerge将第三方库合并到自己的库中。

You have the option to make public classes from the 3rd party library internal. 您可以选择在内部第3方库中进行公共课程。 This way, clients of your code will not be able to access functionality from the 3rd party library (unless they do some kind of hack. For example, I am not sure if someone can use an internal class using some kind of Reflection code). 这样,您的代码的客户端将无法访问第三方库的功能(除非他们进行了某种形式的修改。例如,我不确定是否有人可以使用某种反射代码来使用内部类)。

Take a look at this article 看看这篇文章

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

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