【发布时间】:2021-03-17 18:38:36
【问题描述】:
如何在 Azure Pipelines 中使用强名称对我的程序集进行签名?
目前,我在 Visual Studio 中使用 PFX 文件进行签名。您可以看到 PFX here。当我尝试在当前管道中构建时,对程序集进行签名的指令被完全忽略。 This 不使用强名称进行编译。
【问题讨论】:
标签: .net azure-pipelines strongname dotnet-cli
如何在 Azure Pipelines 中使用强名称对我的程序集进行签名?
目前,我在 Visual Studio 中使用 PFX 文件进行签名。您可以看到 PFX here。当我尝试在当前管道中构建时,对程序集进行签名的指令被完全忽略。 This 不使用强名称进行编译。
【问题讨论】:
标签: .net azure-pipelines strongname dotnet-cli
您可以将 pfx 文件作为安全文件存储在 Azure 管道库中,并使用下载安全文件任务将 pfx 文件下载到您的工作区。
然后将签名密钥导入运行构建的用户的加密存储中。这篇博文介绍了如何使用 powershell 导入 pfx。
https://www.karpach.com/visual-studio-team-services-assembly-signing.htm
Param(
[Parameter(Mandatory=$True,Position=1)]
[string] $PfxFilePath,
[string] $PfxPassword
)
# The path to the snk file we're creating
[string] $snkFilePath = [IO.Path]::GetFileNameWithoutExtension($PfxFilePath) + ".snk";
# Read in the bytes of the pfx file
[byte[]] $pfxBytes = Get-Content $PfxFilePath -Encoding Byte;
# Get a cert object from the pfx bytes with the private key marked as exportable
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2(
$pfxBytes,
$PfxPassword,
[Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable);
# Export a CSP blob from the cert (which is the same format as an SNK file)
[byte[]] $snkBytes = ([Security.Cryptography.RSACryptoServiceProvider]$cert.PrivateKey).ExportCspBlob($true);
# Write the CSP blob/SNK bytes to the snk file
[IO.File]::WriteAllBytes([IO.Path]::Combine([IO.Path]::GetDirectoryName($PfxFilePath), $snkFilePath), $snkBytes);
【讨论】: