我在通过 WiX 安装受密码保护的 PFX 证书时遇到了一些麻烦。
我正在使用 WiX 3.5.2519.0。
我包含一个 PFX 文件,如下所示:
<Binary Id="My.Binary"
SourceFile="$(var.ProjectDir)MyProject$(var.ConfigSuffix).pfx" />
$(var.ConfigSuffix) 的值因解决方案配置而异(例如“(Debug)”、“(Stage)”)。对于“Release”,它被设置为一个空字符串。
我有各种解决方案配置,除了一个使用非密码保护的 PFX 证书,“Release”使用密码保护的 PFX。我通过仅在“Release”配置中有条件地定义 $(var.PfxPassword) 来处理这个问题,然后按如下方式安装证书:
<?ifdef $(var.PfxPassword) ?>
<iis:Certificate
Id="My.Certificate"
StoreName="root"
Overwrite="yes"
Name="My Web Site$(var.ConfigSuffix)"
Request="no"
BinaryKey="MyCertificate.Binary"
StoreLocation="localMachine"
PFXPassword="$(var.PfxPassword)" />
<?else?>
<iis:Certificate
Id="My.Certificate"
StoreName="root"
Overwrite="yes"
Name="My Web Site$(var.ConfigSuffix)"
Request="no"
BinaryKey="MyCertificate.Binary"
StoreLocation="localMachine" />
<?endif?>
我还尝试将“$(var.PfxPassword)”替换为“[PFXPASSWORD]”(已在别处定义),并以纯文本形式替换实际密码。在任何情况下,安装都会失败并显示以下日志片段:
Action start 12:29:02: InstallCertificates.
InstallCertificates: Error 0x80070056: Failed to open PFX file.
InstallCertificates: Error 0x80070056: Failed to get SHA1 hash of certificate.
InstallCertificates: Error 0x80070056: Failed to resolve certificate: LinnRecords.Certificate
CustomAction InstallCertificates returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
Action ended 12:29:02: InstallCertificates. Return value 3.
我相信错误 0x80070056 表示密码不正确,但是我在 PowerShell 中使用了Get-PfxCertificate来验证我使用的密码是否正确。
对于 PFX 文件不使用密码的所有配置,安装不会出现问题。