如何 public 使用 MSBuild 签署项目

How to public sign a project with MSBuild

我有一个 C# .NET Framework 项目,我使用本地系统上的 .pfx 文件对其进行了签名。在 .csproj 文件中设置了以下属性:

<PropertyGroup>
  <SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
  <AssemblyOriginatorKeyFile>keyfile.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>

此文件是开源项目的一部分。我正在尝试创建一个在某些提交上运行的管道。当我提交一些东西时,可以使用存储为 GitHub 秘密的密码安装原始 *.pfx。问题是当分叉回购发出拉取请求时,管道失败,因为 GitHub 秘密对他们不可用。

长话短说,我发现我可以使用 public signing 来达到这个目的。但是,当我尝试使用

构建我的项目时
msbuild src\TcBlackCore\TcBlackCore.csproj -t:Rebuild -p:DelaySign=false -p:PublicSign=true -p:Configuration=Release -p:Platform=AnyCPU -p:TreatWarningsAsErrors=true

我收到以下错误:

CS7102: Compilation options 'PublicSign' and 'CryptoKeyContainer' can't both be specified at the same time

我找不到关于此错误代码的任何信息,除了 one GitHub issue 提到:

ERR_MutuallyExclusiveOptions CS7102

这里有哪些互斥选项? DelaySign 应设置为 docs。我应该怎么做才能让 public 签名工作以便可以构建分叉回购协议?

> msbuild -version
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework

public 符号的问题在于,虽然编译器应用了 public 密钥,但实际上并未对程序集 进行签名。就像汇编上的'mark'

在你的情况下,你不能同时使用CryptoKeYContainerPublicSign,因为它们做的事情几乎相同,因此编译器会提示错误。

出于您的目的,我建议使用 DelaySign - 正如 Microsoft 文档所述:

Use DelaySign - If you want a fully signed assembly. Use DelaySign if you only want to place the public key in the assembly

作为参考,标签是:

<DelaySign>true</DelaySign>