开发者

How do I get the strong name of an assembly?

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 开发者_C百科use it in System.Runtime.CompilerServices.InternalsVisibleTo?


To get the public key of a strong-named assembly, use the sn tool:

sn -Tp assembly.dll

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 the InternalsVisibleTo attribute will need adding to the other assembly - something which you cannot do without recompiling it..


You have to specify fully qualified name and public key token in AssemblyInfo.cs file of assembly you "need a friend":

[assembly: InternalsVisibleTo("FullAssemblyName, PublicKey=....", )]

If you have Reflector.NET or ildasm in hand you can use it to see this information

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜