From 73cd48a3d2f0d4b564990f5223dc6a4078c34f1d Mon Sep 17 00:00:00 2001 From: Paul Medynski <31868385+paulmedynski@users.noreply.github.com> Date: Fri, 21 Aug 2026 11:25:50 -0300 Subject: [PATCH] Add assembly signing for Microsoft.Data.SqlClient.Extensions.Abstractions Sign the Abstractions package and its test assembly on internal Package-mode builds, and make the Abstractions CI jobs actually honour Package mode. - Thread isInternalBuild through the Abstractions stage into the pack and test jobs, downloading the driver and test signing keys as needed. - Add a signed InternalsVisibleTo grant for the test assembly, and sign the test assembly when a test key is supplied. - Pass packageVersion, loggingArtifactsName and referenceType into the test jobs, and download the Logging artifacts, so Package mode is exercised. - Correct the pack job to use the canonical SqlClientPackageVersion and BuildNumber properties instead of undeclared per-package parameters. - Thread signing and reference-type arguments into the build.proj TestAbstractions target. - Build the Abstractions test project for net462 only on Windows hosts. --- build.proj | 14 ++-- eng/pipelines/dotnet-sqlclient-ci-core.yml | 1 + .../jobs/pack-abstractions-package-ci-job.yml | 34 ++++++---- .../jobs/test-abstractions-package-ci-job.yml | 67 +++++++++++++++++-- .../build-abstractions-package-ci-stage.yml | 18 +++++ .../Abstractions/src/Abstractions.csproj | 12 ++++ .../test/Abstractions.Test.csproj | 16 ++++- 7 files changed, 138 insertions(+), 24 deletions(-) diff --git a/build.proj b/build.proj index 9883656f50..c7c70e9e5b 100644 --- a/build.proj +++ b/build.proj @@ -884,22 +884,28 @@ - AbstractionsTests-$(OS) $(LogFilePrefix)-$(TestFramework) "$(DotnetPath)dotnet" test "$(AbstractionsTestProjectPath)" + + -p:Configuration=$(Configuration) + $(SigningKeyPathArgument) + $(TestSigningKeyPathArgument) + + $(TestBlameArgument) $(TestCodeCoverageArgument) $(TestFiltersArgument) $(TestFrameworkArgument) --results-directory "$(TestResultsFolderPath)" --logger:"trx;LogFilePrefix=$(LogFilePrefix)" + + + $(ReferenceTypeArgument) + $(PackageVersionSqlClientArgument) $([System.Text.RegularExpressions.Regex]::Replace($(DotnetCommand), "\s+", " ")) diff --git a/eng/pipelines/dotnet-sqlclient-ci-core.yml b/eng/pipelines/dotnet-sqlclient-ci-core.yml index 36bb1dda1f..1ce914db02 100644 --- a/eng/pipelines/dotnet-sqlclient-ci-core.yml +++ b/eng/pipelines/dotnet-sqlclient-ci-core.yml @@ -183,6 +183,7 @@ stages: dotnetVerbosity: ${{ parameters.dotnetVerbosity }} loggingArtifactsName: $(loggingArtifactsName) referenceType: ${{ parameters.referenceType }} + isInternalBuild: ${{ parameters.isInternalBuild }} # When building Abstractions via packages, we must depend on the Logging # package. ${{ if eq(parameters.referenceType, 'Package') }}: diff --git a/eng/pipelines/jobs/pack-abstractions-package-ci-job.yml b/eng/pipelines/jobs/pack-abstractions-package-ci-job.yml index 8bf43bd997..6a360e9bad 100644 --- a/eng/pipelines/jobs/pack-abstractions-package-ci-job.yml +++ b/eng/pipelines/jobs/pack-abstractions-package-ci-job.yml @@ -15,7 +15,7 @@ parameters: # The name to apply to the published pipeline artifacts. - name: abstractionsArtifactsName type: string - default: Abstractions.Artifact + default: Abstractions.Artifacts # The version to apply to the Abstractions NuGet package and its assemblies. Every package in the # SqlClient family shares this version. @@ -67,6 +67,11 @@ parameters: # Reference sibling packages as C# projects. - Project + # True when building on the internal ADO.Net project. + - name: isInternalBuild + type: boolean + default: false + jobs: - job: pack_abstractions_package_job @@ -130,12 +135,23 @@ jobs: parameters: debug: ${{ parameters.debug }} + # Download the assembly signing key for internal Package-mode builds. + - ${{ if and(eq(parameters.isInternalBuild, true), ne(parameters.referenceType, 'Project')) }}: + - template: /eng/pipelines/common/steps/download-assembly-signing-key.yml@self + # Create the NuGet packages. - # - # When referenceType is Package, we must pass ReferenceType and the - # dependency version so that Directory.Packages.props applies version - # ranges to sibling package dependencies. - - ${{ if eq(parameters.referenceType, 'Package') }}: + - ${{ if and(eq(parameters.referenceType, 'Package'), eq(parameters.isInternalBuild, true)) }}: + - task: DotNetCoreCLI@2 + displayName: Create NuGet Package + inputs: + command: pack + packagesToPack: $(project) + configurationToPack: ${{ parameters.buildConfiguration }} + packDirectory: $(dotnetPackagesDir) + verbosityToPack: ${{ parameters.dotnetVerbosity }} + buildProperties: SqlClientPackageVersion=${{ parameters.packageVersion }};ReferenceType=Package;BuildNumber=$(Build.BuildNumber);SigningKeyPath=$(driverKeyFile.secureFilePath) + + - ${{ elseif eq(parameters.referenceType, 'Package') }}: - task: DotNetCoreCLI@2 displayName: Create NuGet Package inputs: @@ -144,8 +160,6 @@ jobs: configurationToPack: ${{ parameters.buildConfiguration }} packDirectory: $(dotnetPackagesDir) verbosityToPack: ${{ parameters.dotnetVerbosity }} - # BuildNumber supplies the revision component of FileVersion; without - # it the assembly is stamped Major.Minor.Patch.0 (see Project branch). buildProperties: SqlClientPackageVersion=${{ parameters.packageVersion }};ReferenceType=Package;BuildNumber=$(Build.BuildNumber) - ${{ else }}: @@ -157,10 +171,6 @@ jobs: configurationToPack: ${{ parameters.buildConfiguration }} packDirectory: $(dotnetPackagesDir) verbosityToPack: ${{ parameters.dotnetVerbosity }} - # BuildNumber supplies the revision component of FileVersion - # (Major.Minor.Patch.Revision). Without it, FileVersionBuildNumber - # defaults to 0 and the assembly is stamped Major.Minor.Patch.0, - # inconsistent with the MDS/AKV packages that pass it. buildProperties: SqlClientPackageVersion=${{ parameters.packageVersion }};BuildNumber=$(Build.BuildNumber) # Publish the NuGet packages as a named pipeline artifact. diff --git a/eng/pipelines/jobs/test-abstractions-package-ci-job.yml b/eng/pipelines/jobs/test-abstractions-package-ci-job.yml index 83366b52a9..ad423ab807 100644 --- a/eng/pipelines/jobs/test-abstractions-package-ci-job.yml +++ b/eng/pipelines/jobs/test-abstractions-package-ci-job.yml @@ -13,6 +13,18 @@ parameters: + # The name of the Logging pipeline artifacts to download. + # + # This is used when the referenceType is 'Package'. + - name: loggingArtifactsName + type: string + default: Logging.Artifacts + + # The version to apply to the SqlClient family packages. This is used when + # referenceType is 'Package'. + - name: packageVersion + type: string + # The type of build to test (Release or Debug) - name: buildConfiguration type: string @@ -61,6 +73,20 @@ parameters: - name: poolName type: string + # True when building on the internal ADO.Net project. When set, assemblies + # are signed with the driver key and tests are signed with the test key. + - name: isInternalBuild + type: boolean + default: false + + # The C# project reference type to use when building. + - name: referenceType + type: string + default: Project + values: + - Package + - Project + # The pool VM image to use. - name: vmImage type: string @@ -88,12 +114,24 @@ jobs: - name: project value: src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/Abstractions.Test.csproj - # dotnet CLI arguments for build/test/pack commands - - name: buildArguments + # dotnet CLI arguments for build/test commands. + - name: dotnetBuildOpts value: >- -p:Configuration=${{ parameters.buildConfiguration }} + -p:ReferenceType=${{ parameters.referenceType }} + -p:SqlClientPackageVersion=${{ parameters.packageVersion }} --verbosity ${{ parameters.dotnetVerbosity }} + # Signing arguments — only set for internal Package-mode builds. + - ${{ if and(eq(parameters.isInternalBuild, true), ne(parameters.referenceType, 'Project')) }}: + - name: signingArguments + value: >- + -p:SigningKeyPath=$(driverKeyFile.secureFilePath) + -p:TestSigningKeyPath=$(testKeyFile.secureFilePath) + - ${{ else }}: + - name: signingArguments + value: '' + # Explicitly unset the $PLATFORM environment variable that is set by the # 'ADO Build properties' Library in the ADO SqlClientDrivers public project. # This is defined with a non-standard Platform of 'AnyCPU', and will fail @@ -121,6 +159,21 @@ jobs: - pwsh: 'Get-ChildItem Env: | Sort-Object Name' displayName: '[Debug] Print Environment Variables' + # Download the assembly signing keys for internal Package-mode builds. + - ${{ if and(eq(parameters.isInternalBuild, true), ne(parameters.referenceType, 'Project')) }}: + - template: /eng/pipelines/common/steps/download-assembly-signing-key.yml@self + - template: /eng/pipelines/common/steps/download-assembly-signing-key.yml@self + parameters: + isTest: true + + # For Package reference builds, download the Logging dependency into packages/. + - ${{ if eq(parameters.referenceType, 'Package') }}: + - task: DownloadPipelineArtifact@2 + displayName: Download Logging Package Artifacts + inputs: + artifactName: ${{ parameters.loggingArtifactsName }} + targetPath: $(Build.SourcesDirectory)/packages + # Install the .NET SDK and Runtimes. - template: /eng/pipelines/common/steps/install-dotnet.yml@self parameters: @@ -136,7 +189,7 @@ jobs: inputs: command: build projects: $(project) - arguments: $(buildArguments) + arguments: $(dotnetBuildOpts) $(signingArguments) # Run the tests for each .NET runtime. - ${{ each runtime in parameters.netRuntimes }}: @@ -146,7 +199,7 @@ jobs: command: test projects: $(project) arguments: >- - $(buildArguments) + $(dotnetBuildOpts) --no-build -f ${{ runtime }} --filter "category != failing & category != flaky & category != interactive" @@ -157,7 +210,7 @@ jobs: command: test projects: $(project) arguments: >- - $(buildArguments) + $(dotnetBuildOpts) --no-build -f ${{ runtime }} --filter "category = flaky" @@ -170,7 +223,7 @@ jobs: command: test projects: $(project) arguments: >- - $(buildArguments) + $(dotnetBuildOpts) --no-build -f ${{ runtime }} --filter "category != failing & category != flaky & category != interactive" @@ -181,7 +234,7 @@ jobs: command: test projects: $(project) arguments: >- - $(buildArguments) + $(dotnetBuildOpts) --no-build -f ${{ runtime }} --filter "category = flaky" diff --git a/eng/pipelines/stages/build-abstractions-package-ci-stage.yml b/eng/pipelines/stages/build-abstractions-package-ci-stage.yml index 3df0ef9843..b15edb29d3 100644 --- a/eng/pipelines/stages/build-abstractions-package-ci-stage.yml +++ b/eng/pipelines/stages/build-abstractions-package-ci-stage.yml @@ -76,6 +76,11 @@ parameters: # Reference sibling packages as C# projects. - Project + # True when building on the internal ADO.Net project. + - name: isInternalBuild + type: boolean + default: false + stages: - stage: build_abstractions_package_stage @@ -98,14 +103,18 @@ stages: - template: /eng/pipelines/jobs/test-abstractions-package-ci-job.yml@self parameters: + packageVersion: $(packageVersion) buildConfiguration: ${{ parameters.buildConfiguration }} debug: ${{ parameters.debug }} displayNamePrefix: Linux dotnetVerbosity: ${{ parameters.dotnetVerbosity }} + isInternalBuild: ${{ parameters.isInternalBuild }} jobNameSuffix: linux + loggingArtifactsName: ${{ parameters.loggingArtifactsName }} netFrameworkRuntimes: [] netRuntimes: [net8.0, net9.0, net10.0] poolName: Azure Pipelines + referenceType: ${{ parameters.referenceType }} vmImage: ubuntu-latest # ------------------------------------------------------------------------ @@ -113,14 +122,18 @@ stages: - template: /eng/pipelines/jobs/test-abstractions-package-ci-job.yml@self parameters: + packageVersion: $(packageVersion) buildConfiguration: ${{ parameters.buildConfiguration }} debug: ${{ parameters.debug }} displayNamePrefix: Win dotnetVerbosity: ${{ parameters.dotnetVerbosity }} + isInternalBuild: ${{ parameters.isInternalBuild }} jobNameSuffix: windows + loggingArtifactsName: ${{ parameters.loggingArtifactsName }} netFrameworkRuntimes: [net462] netRuntimes: [net8.0, net9.0, net10.0] poolName: Azure Pipelines + referenceType: ${{ parameters.referenceType }} vmImage: windows-latest # ------------------------------------------------------------------------ @@ -128,14 +141,18 @@ stages: - template: /eng/pipelines/jobs/test-abstractions-package-ci-job.yml@self parameters: + packageVersion: $(packageVersion) buildConfiguration: ${{ parameters.buildConfiguration }} debug: ${{ parameters.debug }} displayNamePrefix: macOS dotnetVerbosity: ${{ parameters.dotnetVerbosity }} + isInternalBuild: ${{ parameters.isInternalBuild }} jobNameSuffix: macos + loggingArtifactsName: ${{ parameters.loggingArtifactsName }} netFrameworkRuntimes: [] netRuntimes: [net8.0, net9.0, net10.0] poolName: Azure Pipelines + referenceType: ${{ parameters.referenceType }} vmImage: macos-latest # ------------------------------------------------------------------------ @@ -157,3 +174,4 @@ stages: dotnetVerbosity: ${{ parameters.dotnetVerbosity }} loggingArtifactsName: ${{ parameters.loggingArtifactsName }} referenceType: ${{ parameters.referenceType }} + isInternalBuild: ${{ parameters.isInternalBuild }} diff --git a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj index e8b3c55ba0..8826080981 100644 --- a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj +++ b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj @@ -33,10 +33,22 @@ + + + + + + + $(RepoRoot)artifacts/ diff --git a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/Abstractions.Test.csproj b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/Abstractions.Test.csproj index 427a7aaf9f..8a80c24a51 100644 --- a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/Abstractions.Test.csproj +++ b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/Abstractions.Test.csproj @@ -2,12 +2,26 @@ Microsoft.Data.SqlClient.Extensions.Abstractions.Test - net462;net8.0;net9.0;net10.0 + net8.0;net9.0;net10.0 + + + $(TargetFrameworks);net462 false true + + + + true + $(TestSigningKeyPath) + + enable