【发布时间】:2020-06-17 17:12:43
【问题描述】:
我在 gitlab 中有一个 .net-core 3.1 项目 (Microsoft.NET.Sdk.Web),并且正在为其设置 CI/CD 管道。作为最后一步,我希望所有 .dll 和 .exe 输出文件都由我们的密钥签名。我可以通过手动将一些“signtool”命令作为 gitlab-ci.yml 文件的一部分来执行此操作,但这需要进入每个项目并手动调整文件以反映该项目的具体情况。
另一方面,我已经能够在 .csproj 文件中添加一个通用目标,该文件调用 signtool 作为 $(TargetDir)$(TargetFileName) 上的执行/命令。这在一定程度上有效 - 但它并没有签署所有内容。在这种情况下,它签署(例如)cthulhu.dll,但不签署 cthulhu.Views.dll(两者都显示在 'dotnet msbuild' 的 CLI 输出中),还有一个 cthulhu.exe 已生成但未生成显示在 msbuild 输出中,也未签名。
csproj 文件将此作为目标(尝试在重建后和发布后运行):
<Target Name="SignAssembly" AfterTargets="Rebuild">
<Message Text="Signing assembly '$(TargetDir)$(TargetFileName)'" Importance="high" />
<Exec Command="signtool sign /f "mykey.pfx" /p "snip" /tr http://timestamp.digicert.com "$(TargetDir)$(TargetFileName)"" />
并且 gitlab-ci.yml 文件看起来像这样(我知道我正在使用 sdk docker 容器,但它似乎让我无论如何都支持 .net-core 构建,而有一个错误阻止了特定的 .net-core 容器工作):
image: mcr.microsoft.com/dotnet/framework/sdk:4.8
stages:
- build
- release
build:
stage: build
script:
- 'dotnet build -r win-x64'
release:
stage: release
script:
- 'dotnet add package signtool --version 10.0.17763.132'
- 'dotnet msbuild cthulhu.csproj /t:"Restore;Rebuild;SignAssembly;Publish" /p:SelfContained=True /p:PublishProtocol=FileSystem /p:Configuration=Release /p:Platform=x64 /p:TargetFrameworks=netcoreapp3.1 /p:PublishDir=bin\Release\netcoreapp3.1\publish\win-x64 /p:RuntimeIdentifier=win-x64 /p:PublishReadyToRun=False /p:PublishTrimmed=True'
artifacts:
name: "$CI_JOB_STAGE-$CI_COMMIT_REF_NAME"
paths:
- '.\bin\Release\netcoreapp3.1\publish\win-x64'
【问题讨论】:
标签: c# .net-core msbuild gitlab-ci signtool