如何禁止一个.NET的DLL类库引用 [英] How to forbid a .NET DLL class library to be referenced

查看:271
本文介绍了如何禁止一个.NET的DLL类库引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何禁止DLL类库中的其他解决方案中引用?

How can I forbid dll class library to be referenced in other solutions?

推荐答案

您可以考虑增加一个<一个href="http://msdn.microsoft.com/en-us/library/system.security.permissions.strongnameidentitypermission.aspx"相对=nofollow> StrongNameIdentityPermission 您的类库匹配的程序的强名称你的的希望能够使用它。

You could look into adding a StrongNameIdentityPermission to your class library that matches the strong name of the program you do want to be able to use it with.

另外,你可以探索使用<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx"相对=nofollow> InternalsVisibleToAttribute ,尽管它可能需要在您的图书馆code一些设计变更。这应该既不组件签名,或两者都具有强名称签名,只要工作。在属性指定的参数应与公共密钥和您希望能够访问其内部成员的程序集的名称。

Alternatively, you could explore using InternalsVisibleToAttribute, although it may require some design changes in your library code. This should work as long as neither assembly is signed, or both are signed with a strong name. The argument specified on the attribute should match the public key and the name of the assembly that you want to be able to access its internal members.

不过说真的,这只会阻止别人谁不拼命用你的库。他们将不能够添加引用,但它并没有prevent有人通过反射绕过它或拆卸您的code。总有办法周围几乎你实现任何安全措施。

But really, this will only stop someone who isn't trying very hard to use your library. They won't be able to add a reference, but it doesn't prevent someone from bypassing it through Reflection or disassembling your code. There are always ways around almost any security measure that you implement.

这篇关于如何禁止一个.NET的DLL类库引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆