所选证书对于编码签名无效

Al *_*ath 5 powershell clickonce certificate

我有以下 Powershell 脚本来为 C# 应用程序创建新证书:

$expirationDate = [datetime]::Today.AddYears(5)
$thumb = (New-SelfSignedCertificate -CertStoreLocation cert:\localmachine\my -DnsName $env:USERDNSDOMAIN -KeyExportPolicy Exportable -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" -NotAfter $expirationDate).Thumbprint
$pwd = '123456'
$SSpwd = ConvertTo-SecureString -String $pwd -Force -AsPlainText
$destinationDirectory = "C:\Test\" 
$filename = "mycert.pfx"
$pathAndFilename = $destinationDirectory + $filename
Export-PfxCertificate -cert "cert:\localmachine\my\$thumb" -FilePath $pathAndFilename -Password $SSpwd
Run Code Online (Sandbox Code Playgroud)

它运行良好。然后在 Visual Studio 的应用程序中,在项目属性页面的“签名”选项卡上,单击“从文件中选择”并浏览到该文件,我得到:

所选证书对于编码签名无效。选择另一个证书文件。

我究竟做错了什么?

显示现有证书的“签名”选项卡的屏幕截图

根据@ConnorLSW 评论添加信息。我现在有这个脚本:

$pwd = '123456'
$SSpwd = ConvertTo-SecureString -String $pwd -Force -AsPlainText
$destinationDirectory = "C:\Test\" 
$filename = "mycert.pfx"
$pathAndFilename = $destinationDirectory + $filename
Import-PfxCertificate -cert "cert:\localmachine\my" -FilePath $pathAndFilename -Password $SSpwd
Run Code Online (Sandbox Code Playgroud)

其输出:

目录:Microsoft.PowerShell.Security\Certificate::LocalMachine\我的
指纹主题
AA1032E160156EC22D4447967A8B6401FF25E838 CN=AAAA.BBBB.CC.DDD

那里没有提到用法,并且在文档中我没有看到任何用法。我如何获得这些信息?

Bac*_*its 4

您需要运行New-SelfSignedCertificatewith-Type CodeSigningCert来获取可用于代码签名的证书。

是的,这个Get-Help页面New-SelfSignedCertificate超级无用。

[请注意,我看不到您的屏幕截图,因为该图像主机在我的网络上被阻止。]