具有 InternalsVisibleTo 的 Moles 会创建“程序集引用无效”警告

发布于 2024-12-23 16:33:16 字数 656 浏览 2 评论 0原文

又一年,又一个关于鼹鼠的问题。我有一个带有内部密封类的程序集,我想在用于单元测试的测试项目中使用它。

根据 Moles 文档,我应该添加一个

[assembly: InternalsVisibleTo( "MyAssembly.Moles" )]

属性,以便我可以从我的测试项目访问内部类。然而,不幸的是,这不起作用,因为“MyAssembly”是强签名的。

因此,按照文档,我将公钥添加到上面的行中,导致

[assembly: InternalsVisibleTo( "MyAssembly.Moles, PublicKey=0123456..." )]

不幸的是,现在在编译“MyAssembly”时出现以下错误:

程序集引用“MyMoles.Moles, PublicKey=0123456...”无效且无法解析

该文档说“...Moles 框架始终使用相同的密钥来签署程序集...”,但正如编译器所说,这不起作用。我还使用 Reflector 检查了生成的文件“MyAssembly.Moles.dll”,以验证我是否使用了正确的公钥(我确实这样做了),所以我陷入了困境,因为我真的不知道问题是什么。

有什么想法吗?

Another year, another question about Moles. I've got an assembly with an internal sealed class that I'd like to mole in the test project that I use for unit tests.

According to the Moles documentation I should add an

[assembly: InternalsVisibleTo( "MyAssembly.Moles" )]

attribute so I can access the internal class from my test project. However, this unfortunately doesn't work as "MyAssembly" is strongly signed.

Therefore, following the documentation, I added the Public Key to the line above, resulting in

[assembly: InternalsVisibleTo( "MyAssembly.Moles, PublicKey=0123456..." )]

Unfortunately this now gives me the following error when compiling "MyAssembly":

Assembly reference 'MyMoles.Moles, PublicKey=0123456...' is invalid and cannot be resolved

The documentation says that "...the Moles framework always uses the same key to sign the assembly...", but as the compiler says, this does not work. I also checked the generated file "MyAssembly.Moles.dll" with Reflector to verify that I use the correct public key (which I do), so I am stuck as I don't really know what the problem is.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡绿茶香 2024-12-30 16:33:16

确保您输入的是公钥,而不是公钥令牌

如果这不起作用,请使用 secutil 来获取公钥。详细输出将包含正确的键值。这是您需要使用的语法:

C:\> secutil -hex -s MyAssemblyName.dll

Be sure you are entering the PUBLIC KEY, and not the PUBLIC KEY TOKEN.

If that doesn't work, use the secutil, to get the public key. The verbose output will include the correct key value. This is the syntax you need to use:

C:\> secutil -hex -s MyAssemblyName.dll
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文