sql-server - 由于公共(public) token 不匹配,从源运行 tSQLt 项目失败

标签 sql-server pfx tsqlt snk

我正在尝试做 some improvements对于 tSQLt 框架,我已经基本完成,但无法做到这一点,因为与我没有接触的证书相关的一些测试仍然失败:

 [exec] |18|[InstallExternalAccessKeyTests].[test creates correct certificate in master]                                                       |    120|Failure|
 [exec] |19|[InstallExternalAccessKeyTests].[test tSQLt can be set to EXTERNAL ACCESS after InstallExternalAccessKey executed]                 |    333|Failure|
 [exec] |20|[InstallExternalAccessKeyTests].[test tSQLtExternalAccessKey install data is signed with same key as tSQLt.clr]                    |     10|Failure|

失败的错误是:

Expected: %publickeytoken=8c9a92de0f9c7794,%
Actual: tsqltclr, version=1.0.7216.13228, culture=neutral, publickeytoken=8d3f4bf59e4c22fd, processorarchitecture=msil

我将尝试描述我的安装过程。

我使用following guideline安装了这个框架源。然而,此后我无法启动该项目,因为它因以下错误而失败,并且整个问题的解决都是在 SO post 中完成的。 :

[exec]
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(2482,5): error MSB3325: Cannot import the following key file: tSQLtOfficialSigningKey.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_C20B79DE0583A5C1 [E:\Source\tSQLt\tSQLtCLR\tSQLtCLR\tSQLtCLR.csproj] [exec]
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(2482,5): error MSB3321: Importing key file "tSQLtOfficialSigningKey.pfx" was canceled. [E:\Source\tSQLt\tSQLtCLR\tSQLtCLR\tSQLtCLR.csproj]

为了解决这个问题,我为每个项目创建了没有密码的新 key :

enter image description here

我看到它创建了 snk 文件,而不是原始的 pfx 文件。之后,我尝试再次运行构建,但由于我上面提到的错误而失败。

最佳答案

如上所述here

为 Microsoft Visual Studio 2008 - 2015 构建项目时可能会出现以下错误。

错误:无法导入以下 key 文件:mykey.pfx。 key 文件可能受密码保护。

Cannot import the following key file: mykey.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_C1D3ACB8FBF1AGK4

解决方案 1:

单击“开始”>“所有程序”>“Microsoft Visual Studio”>“Visual Studio” 工具 > Visual Studio 命令提示符。输入以下命令

sn -i "c:\Pathtofile\.pfx" VS_KEY_C1D3ACB8FBF1AGK4

注意:带 -i 参数的 sn.exe 将 key 对安装到名为的 key 容器中。重新导入 PFX 文件到 Visual Studio 中。

解决方案 2:

  • 打开项目属性。

  • 点击“签名”部分。

  • 如果显示“选择强名称 key 文件:”,请从下拉框中重新选择当前值

  • Visual Studio 现在将提示您输入密码。输入它。您可能会收到另一条错误消息: “尝试引用不存在的 token ”> 您可以忽略此消息。

  • 点击“更改密码”按钮

  • 在所有三个框中输入原始密码,然后单击“确定”。如果你想改变

  • 您的密码(或者如果您的旧密码不符合复杂性要求),您现在就可以这样做。

  • 对项目中的每个 key 文件重复此操作。 保存您的项目并进行重建。

解决方案 3:

从 slproweb.com 获取 Windows 版 openssl 的副本,或者使用 Linux 盒子,因为他们几乎都有。 运行以下命令导出到 key 文件

openssl pkcs12 -in certfile.pfx -out backupcertfile.key

openssl pkcs12 -export -out certfiletosignwith.pfx -keysig -in backupcertfile.key

然后在项目属性中您可以使用 PFX 文件

解决方案 4:

此问题的最终解决方案是放弃使用 Visual Studio 进行签名,转而使用 Signtool

更新答案

您的 TFS 构建服务帐户似乎没有访问构建代理计算机上的signingKey.pfx 所需的权限。 首先确保您在构建代理计算机上有此文件。

然后按照以下步骤操作:

  1. 您的本地构建服务帐户身份登录构建代理(最好具有管理员权限)

  2. 打开 Visual Studio 命令提示符并导航到目录 key 存储在

  3. 键入命令 sn –isigningKey.pfx VS_KEY_EFCA4C5B6DFD4B4F(确保您使用错误消息中出现的 key 名称)

  4. 当提示输入密码时,输入 pfx 文件的密码

  5. 然后重建它

注意:如果您没有以管理员身份运行 Visual Studio,也请尝试这样做。

更多详情可以引用Brandon Manchester的回答Cannot import the keyfile 'blah.pfx' - error 'The keyfile may be password protected'

关于sql-server - 由于公共(public) token 不匹配,从源运行 tSQLt 项目失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58602752/

相关文章:

c# - 不支持 SQL Server 表值参数列。类型是 'Object'

SQL Server ALTER 字段 NOT NULL 需要永远

pfx - 为什么在尝试使用 signtool 签署应用程序时会收到 "The specified PFX password is not correct"?

powershell - 在 Azure Web App 中安装根证书和中间证书?

sql - 如何获得 MAX int 但排除特定的 int?

tsqlt - 如何忽略tSQLt AssertEqualsTable中的列?

c# - 使用 C# 在 asp.net 中的 SQL Server 中保存和检索图像

c# - 跟踪更改并从 Mysql -> MSSQL 进行更改的最佳方法

c++ - 使用 CryptoAPI 从 PFX 证书获取 X509 数据

visual-studio-2012 - tSQLt 项目无法在 Visual Studio 2012 中生成