我有 .pfx 证书已使用“下载安全文件”任务下载到我的build.sourceDirectory
. 现在我想将该证书仅分配给一个项目,而不是所有项目
尝试了一个 PowerShell 脚本,但它抛出以下错误。如果有任何错误,请提出任何其他替代方案或更正脚本
找不到“导入”和参数计数的重载:“2”。在 D:\a_temp\88829cbf-115f-4b06-aa8a-c072600792f7.ps1:10 char:1 + $cert.Import($pfxpath, $password) + ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException +fullyQualifiedErrorId : MethodCountCouldNotFindBest
$pfxpath = '$(Build.SourceDirectory)\cert.pf'
$password = '{password}'
Add-Type -AssemblyName System.Security
$cert = New-Object
System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.Import($pfxpath, $password )
$store = new-object system.security.cryptography.X509Certificates.X509Store
-argumentlist "MY", CurrentUser
`$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]"ReadWrite")`
$store.Add($cert)
$store.Close()
您可能会错过 Method 的参数import
。官方文档显示需要为导入方法指定一个存储标志。有关X509KeyStorageFlags 的详细信息。
Import(String, String, X509KeyStorageFlags)
有关Import 的更多用法,请查看这里
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句