Skip to content

Commit f637eda

Browse files
committed
Add signing to dnup library package using SignTool
This is a clean commit since I had to merge with main to get the initial CI working during my development branch. Please see the branch `nagilson-dnup-nuget-sign` on origin (nagilson) or upstream (dotnet/sdk) in public if you want the history of these changes. - CI now properly signs the library package for internal consumption. The actual additions: `src/Installer/Microsoft.Dotnet.Installation/Install.sign.proj` -> uses `SignTool` to sign the `dnup library` package with NuGet's Authenticode. `eng/pipelines/templates/jobs/dnup/dnup-library-package.yml` -> now runs the .sign.proj to sign the library package. Notes: - `.sign.proj` is used over `.signproj` as a convention because `code` and other editors don't have xml highlighting for `.signproj` - I considered the ESRP/MicroBuild/SignTool task but felt this was more traceable to call via MSBuild - since the binlog shows all of the 'hidden' arcade magic and variables that flow around. - I was surprised to find that having a very simple `FilesToSign` itemgroup (as many other repos do) and that following the internal documentation for signing a nuget package did not work. `SignTool` was the most robust way I could find to do it. See the drop at https://dev.azure.com/dnceng/internal/_build/results?buildId=2828736&view=artifacts&pathAsName=false&type=publishedArtifacts, download the `dnup-library-packages-unsigned` artifact (which is incorrect, I'm fixing that), clone dotnet/arcade, build, and run `.\artifacts\bin\Microsoft.DotNet.SignCheck\x86\Debug\net472\Microsoft.DotNet.SignCheck.exe -v Detailed -i "drop_path"` or `dotnet nuget verify "drop_path" -v Detailed`
1 parent 72f4fb4 commit f637eda

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

eng/pipelines/templates/jobs/dnup/dnup-library-package.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ jobs:
4444
targetPath: '$(Build.SourcesDirectory)/artifacts/packages/Release/NonShipping/'
4545
artifactName: 'dnup-library-packages'
4646
publishLocation: Container
47-
4847
steps:
4948
- ${{ if eq(parameters.pool.os, 'windows') }}:
5049
- powershell: |
@@ -54,5 +53,11 @@ jobs:
5453
& .\.dotnet\dotnet build test\dnup.Tests\dnup.Tests.csproj -c Release
5554
displayName: 💻 Build Windows
5655
- powershell: |
57-
& .\.dotnet\dotnet pack .\src\Installer\Microsoft.Dotnet.Installation\Microsoft.Dotnet.Installation.csproj
56+
& .\.dotnet\dotnet pack .\src\Installer\Microsoft.Dotnet.Installation\Microsoft.Dotnet.Installation.csproj
5857
displayName: 📦 Package dnup library
58+
- powershell: |
59+
& .\.dotnet\dotnet build .\src\Installer\Microsoft.Dotnet.Installation\Microsoft.Dotnet.Installation.sign.proj
60+
displayName: 🖋️ Sign dnup library packages with full.sign.proj (no sign target)
61+
- powershell: |
62+
& .\.dotnet\dotnet build .\src\Installer\Microsoft.Dotnet.Installation\Microsoft.Dotnet.Installation.sign.proj /t:Sign
63+
displayName: 🖋️ Sign dnup library packages with arcade signtool
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net10.0</TargetFramework>
4+
<!-- Determine repository root when the pipeline variables are unavailable (e.g. local invocations). -->
5+
<_RepoRoot Condition="'$(RepoRoot)' != ''">$(RepoRoot)</_RepoRoot>
6+
<_RepoRoot Condition="'$(_RepoRoot)' == ''">$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\..\'))</_RepoRoot>
7+
8+
<!-- Allow callers to override these directories; fall back to repo-relative defaults. -->
9+
<PackagesDir Condition="'$(PackagesDir)' == ''">$(_RepoRoot)artifacts\packages\Release\</PackagesDir>
10+
<IntermediateOutputPath Condition="'$(IntermediateOutputPath)' == ''">$(_RepoRoot)artifacts\obj\Sign\</IntermediateOutputPath>
11+
<LogDir Condition="'$(LogDir)' == ''">$(_RepoRoot)artifacts\log\Sign\</LogDir>
12+
13+
<!-- SignTool requires explicit dotnet path; default to repo-local SDK. -->
14+
<DotNetPath Condition="'$(DotNetPath)' == ''">$(_RepoRoot).dotnet\dotnet.exe</DotNetPath>
15+
16+
<MicroBuild_DoNotStrongNameSign>true</MicroBuild_DoNotStrongNameSign>
17+
<MicroBuild_SigningEnabled>true</MicroBuild_SigningEnabled>
18+
</PropertyGroup>
19+
20+
<Import Project="$(NuGetPackageRoot)microsoft.dotnet.signtool\$(MicrosoftDotNetSignToolVersion)\build\Microsoft.DotNet.SignTool.props" />
21+
22+
<!-- The name of the .NET specific certificate, which is a general replacement for Microsoft400
23+
If UseDotNetCert is specific in a repo's eng/Signing.props, all usage of Microsoft400 is replaced
24+
with MicrosoftDotNet500 -->
25+
<PropertyGroup>
26+
<DotNetCertificateName>MicrosoftDotNet500</DotNetCertificateName>
27+
<UseDotNetCertificate>false</UseDotNetCertificate>
28+
</PropertyGroup>
29+
30+
<ItemGroup>
31+
<FileExtensionSignInfo Include=".nupkg" CertificateName="NuGet" />
32+
<FileExtensionSignInfo Include=".dll" CertificateName="Microsoft400" />
33+
<FileSignInfo Include="Microsoft.Dotnet.Installation.dll" CertificateName="Microsoft400" />
34+
<FileSignInfo Include="Microsoft.Dotnet.Installation*.nupkg" CertificateName="NuGet" />
35+
<ItemsToSign Include="$(PackagesDir)**\Microsoft.Dotnet.Installation*.nupkg">
36+
<Authenticode>NuGet</Authenticode>
37+
</ItemsToSign>
38+
</ItemGroup>
39+
40+
<PropertyGroup Condition="'$(SignType)' == ''">
41+
<SignType>test</SignType>
42+
<TestSign>true</TestSign>
43+
</PropertyGroup>
44+
45+
<PropertyGroup Condition="'$(TestSign)' == ''">
46+
<TestSign>false</TestSign>
47+
</PropertyGroup>
48+
49+
50+
<Target Name="Sign" AfterTargets="Build">
51+
<Microsoft.DotNet.SignTool.SignToolTask
52+
DryRun="false"
53+
TestSign="$(TestSign)"
54+
ItemsToSign="@(ItemsToSign)"
55+
FileSignInfo="@(FileSignInfo)"
56+
FileExtensionSignInfo="@(FileExtensionSignInfo)"
57+
TempDir="$(IntermediateOutputPath)"
58+
LogDir="$(LogDir)"
59+
DoStrongNameCheck="false"
60+
DotNetPath="$(DotNetPath)"
61+
MicroBuildCorePath="$(NuGetPackageRoot)microsoft.visualstudioeng.microbuild.core\$(MicrosoftVisualStudioEngMicroBuildCoreVersion)"
62+
SNBinaryPath="$(NuGetPackageRoot)sn\$(SNVersion)\sn.exe"
63+
>
64+
</Microsoft.DotNet.SignTool.SignToolTask>
65+
</Target>
66+
</Project>

0 commit comments

Comments
 (0)