查找 Visual Studio 的安全名称 (sn.exe) 容器名称

Find the secure name (sn.exe) container name for Visual Studio

我有一个软件在构建期间必须由 pfx 证书签名。我在其上构建解决方案的机器是一台全新的机器,我们试图在构建过程中不手动执行任何配置,而是仅通过脚本。

当我启动构建时,我从 msbuild

收到此错误

[error]C:\Program Files (x86)\Microsoft Visual Studio17\Community\MSBuild.0\Bin\Microsoft.Common.CurrentVersion.targets(3214,5):

Error MSB3325: Cannot import the following key file: Key.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_07C5CCD85188D111

通常我通过在构建机器上 Visual Studio 的开发者控制台中执行来解决这个问题:

sn -i VS_KEY_07C5CCD85188D111 path\to\Key.pfx

但是,如前所述,我希望构建自动检索容器名称并导入证书作为 msbuild 命令之前的一个步骤。我遇到的问题是我不知道如何检索 Visual Studio 想要使用的容器名称,因为它会根据我 运行 构建的机器而改变。

您知道 Visual Studio 是如何计算容器名称的吗?或者无论如何如何检索它?

您可以使用SnInstallPfx.exe。它将确定容器名称并导入 pfx。它不是标准的,但使用标准方法来确定容器名称

有关详细信息,请参阅以下内容blog article