强名sn.exe:无法安装密钥对-对象已存在 [英] Strong Name sn.exe: Failed to install key pair -- Object already exists

查看:74
本文介绍了强名sn.exe:无法安装密钥对-对象已存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的机器上有2个不同版本的同一项目.一个来自代码主干,另一个来自代码分支.这些项目使用.pfx密钥来启用强命名.当我第一次尝试编译项目的主干版本时,出现以下错误:

I have 2 different versions of the same project on my machine. One from the code trunk, and the other from a code branch. These projects use a .pfx key to enable strong naming. When I first tried to compile the trunk version of the project I get the following error:

无法导入以下密钥文件:sgKey.pfx.密钥文件可能受密码保护.若要更正此问题,请尝试再次导入证书,或使用以下密钥容器名称将证书手动安装到强名称" CSP:VS_KEY_45891C38BC1BB345

要解决此问题,我将sn.exe与以下命令配合使用:

To resolve this I use sn.exe with the following command:

sn -i sg Key.pfx VS_KEY_45891C38BC1BB345

这解决了中继项目的问题,该项目随后很高兴地构建.

This resolves the issue with the trunk project, which then happily builds.

但是,当我尝试构建项目的分支版本时,会收到相同的初始错误(具有相同的密钥容器名称),并且当我尝试使用sn.exe安装证书时(毫不奇怪),它给出了以下错误:

However, when I try to build the branch version of the project, I receive the same initial error (with the same key container name), and when I try install the certificate using the sn.exe it (not surprisingly) gives the following error:

无法安装密钥对-对象已存在

这很有意义,因为我在sn命令上使用了相同的 infile 容器,但是我想了解的是:

This makes sense in that I used the same infile and container on the sn command, but what I am trying to understand is:

  1. 如果该对象已经存在,为什么项目无法构建,因为它似乎已经安装了证书.
  2. 我该如何解决(例如,我可以先卸载然后重新安装吗?如果可以,怎么办?)

推荐答案

我已经设法解决了我的问题,而没有完全了解原因.我在此处上找到了有关类似问题的帖子.,但由于我只以一个用户身份登录过我的计算机,因此不完全适合我的情况.

I have managed to resolve my issue, without fully understanding the cause. I found a post about a similar issue here, but did not fit my circumstance precisely, as I had only ever logged on to my machine as a single user.

该帖子显示了如何删除容器,但是我也无法做到这一点,因为它说该容器不存在.尽管这样做是提示我以管理员身份运行命令提示符,但以前没有这样做.这样就可以卸载并重新安装证书,并且现在可以成功构建项目的两个版本.

The post showed how to delete the container, but I couldn't do this either as it said the container didn't exist. What it did though was prompt me to run the command prompt as an Administrator, which I had not done previously. This allowed me to uninstall and re-install the certificate, and both versions of the project now build successfully.

我的假设是,证书最初以某种方式(由我)以不同于我第二次尝试安装的用户身份(由我)安装,尽管我不知道为什么会这样,因为我只有一次以单个用户身份登录到计算机.对我来说,这仍然是个谜.

My assumption is that somehow the certificate had initially been installed (by me) under a different user than the one I tried to install with the second time, though I don't know why this would be, as I have only ever logged on to the machine as a single user. It remains something of a mystery to me.

摘要:

  1. 以管理员身份启动开发者命令提示符,否则您将收到一个误导性错误,指出该容器不存在.
  2. 运行sn -d VS_KEY_XXXXXXXXXXX以删除旧密钥.
  3. 您现在应该可以重新安装证书.
  1. Start the developer command prompt as administrator, otherwise you'll get a misleading error saying the container doesn't exist.
  2. Run sn -d VS_KEY_XXXXXXXXXXX to remove the old key.
  3. You should now be able to reinstall the certificate.

这篇关于强名sn.exe:无法安装密钥对-对象已存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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