【问题标题】:Strong Name Signing Azure Pipelines强名称签名 Azure Pipelines
【发布时间】:2021-03-17 18:38:36
【问题描述】:

如何在 Azure Pipelines 中使用强名称对我的程序集进行签名?

目前,我在 Visual Studio 中使用 PFX 文件进行签名。您可以看到 PFX here。当我尝试在当前管道中构建时,对程序集进行签名的指令被完全忽略。 This 不使用强名称进行编译。

【问题讨论】:

    标签: .net azure-pipelines strongname dotnet-cli


    【解决方案1】:

    您可以将 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);
    

    【讨论】:

    • 感谢您的回答。这很复杂。我希望管道能有这个任务。但是,如果不是,这可能就是答案。
    • 嗨 @Christian Findlay,我在 Marketplace 上搜索了 Extensions for Azure DevOps,但没有找到任何可用的强名称签名程序集的扩展或任务。 jessehouwing分享的答案是goos解决方案,你可以标记为这个ticket的解决方案。这可能会帮助更多有类似问题的人在寻找解决方案时。
    猜你喜欢
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-06
    • 1970-01-01
    • 1970-01-01
    • 2022-07-22
    相关资源
    最近更新 更多