如何修复 .Net 中使用 Moq 时出现的 StrongNameKeyPair 错误?
据我所知,有必要有权在机器密钥存储中写入。那么如何将这个权限分配给用户呢?我需要请求支持人员授予用户运行 Moq 所需的权限,但我不知道到底要请求什么。
更新:按照 Tim 下面的要求,我正在更新一些可能对理解问题有用的信息,如下所示:
显然,Moq 依赖 Castle 来构建模拟对象,并且 Castle 框架需要写入机器密钥存储。当我尝试运行测试时,测试框架返回错误“无法获取 StrongNameKeyPair 的公钥”。
当我去支持人员时,他们暂时给了我管理权限,一切都按预期进行。即使他们删除了管理员权限,我仍然能够执行我的测试。
我的结论是,我需要一些权限才能在此计算机密钥存储上写入。我需要知道的是我到底需要在哪里拥有写入权限,所以我可以请求支持特定的写入权限而不是管理员权限,对于其他开发环境,肯定会被拒绝。
提前致谢!
As far as I can see, it is necessary to have access to write in the machine key store. So how do I assign this permission to a user? I need to ask support people to grant a user the necessary permissions to run Moq, but I don't know what exactly to ask for.
UPDATE: As Tim requested below, I'm updating with some information that might be useful to the problem understanding, as follows:
Apparently, Moq relies on Castle to build mock objects, and the Castle framework needs to write to machine key store. When I try to run the tests, the testing framework return the error "Unable to obtain public key for StrongNameKeyPair".
When I went to support guys, they temporarily gave me administrative privileges, and everything ran as expected. Even after they removed the admin permissions, I was able to execute my tests.
My conclusion of this was that I need some permission to write on this machine key store. What I need to know is where exactly I need to have writing permissions, so I could ask support for a specific writing permission instead of admin permissions, for the other development environments, what would be denied for sure.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
经过一番研究,我找到了执行 Moq 所需的写入权限的确切目录(事实上,这是 Castle 的要求)。用户必须有权访问以下文件夹:
C:\Documents and Settings\AllUsers\ApplicationData\Microsoft\Crypto\RSA\MachineKeys
(假设“C”是您的系统文件夹)
拥有此权限,用户可以使用 Moq 运行模拟项目不需要本地计算机的管理权限。这是一个参考:
使用模拟框架进行 MVC 测试 (Moq)
希望有帮助。
After some research, I was able to find the exact directory I need to have write permission in order to execute Moq (in fact, it's a Castle requirement). The user must have acces to the following folder:
C:\Documents and Settings\AllUsers\ApplicationData\Microsoft\Crypto\RSA\MachineKeys
(Assuming "C" is your system folder)
With this permission, the user running a mocking project with Moq won't need admministrative privileges in the local machine. Here is a reference:
MVC Testing using a mocking framework (Moq)
Hope it helps.
我从来不需要安装任何密钥来运行 Moq,无论是在我的工作站本地还是在我们的构建服务器上。我认为你可能需要在你的问题上多做一些工作。您遇到某种错误吗?也许如果您发布了该消息,您可能会得到更好的回复。
I've never needed to install any keys to run Moq, neither locally on my workstation nor on our build server. I think you might need to put a bit more work into your question. Are you getting some sort of error? Perhaps if you posted the message you might get a better response.
添加到 MjLogan 答案;在 Windows 10 中,位置为 C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys
在“MachineKeys”文件夹的属性中,将用户权限设置为完全控制。
Adding to MjLogan Answer; In Windows 10, the location is C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys
In Properties of 'MachineKeys' folder Set Permission of Users to Full Control.