如何获得程序集的强名称?
我需要'加好友'一个不是我创作的 dll 库。
我可以在属性中看到它具有强名称,但如何找出强名称是什么,以便可以在 System.Runtime.CompilerServices.InternalsVisibleTo 中使用它?
I need to 'friend' a dll library that I didn't author.
I can see in the properties that it has a strong name, but how can I find out what the strong name is, so I can use it in System.Runtime.CompilerServices.InternalsVisibleTo
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要获取强名称程序集的公钥,请使用 sn 工具:
这将向您显示需要放入
InternalsVisibleTo
属性中的公钥。如果打开 Visual Studio 命令提示符,sn.exe 工具将已位于路径中。但是,我会质疑你真正想要实现的目标。如果您有一个不是您编写的已编译程序集,则将
InternalsVisibleTo
属性添加到您的代码中将使其能够访问代码的内部结构,但如果没有友元访问权限,它就不会编译。如果您尝试访问其他程序集的内部结构,则InternalsVisibleTo
属性将需要添加到其他程序集 - 如果不重新编译它就无法做到这一点。To get the public key of a strong-named assembly, use the sn tool:
This will show you the public key that you need to put in the
InternalsVisibleTo
attribute. If you open a Visual Studio command prompt, the sn.exe tool will already be in the path.However, I would question what you are trying to actually achieve. If you have a compiled assembly that you did not write, adding the
InternalsVisibleTo
attribute to your code will let it access the internals of your code, but it wouldn't have compiled without already having friend access. If you are trying to access the internals of the other assembly, then theInternalsVisibleTo
attribute will need adding to the other assembly - something which you cannot do without recompiling it..您必须在您“需要一个朋友”的程序集的 AssemblyInfo.cs 文件中指定完全限定名称和公钥令牌:
如果您手头有 Reflector.NET 或 ildasm,您可以使用它来查看此信息
You have to specify fully qualified name and public key token in AssemblyInfo.cs file of assembly you "need a friend":
If you have Reflector.NET or ildasm in hand you can use it to see this information