Skip to content

Enable InternalsVisibleTo for UnitTests in Package mode#4300

Open
paulmedynski wants to merge 4 commits into
mainfrom
dev/paul/internals-package-mode
Open

Enable InternalsVisibleTo for UnitTests in Package mode#4300
paulmedynski wants to merge 4 commits into
mainfrom
dev/paul/internals-package-mode

Conversation

@paulmedynski
Copy link
Copy Markdown
Contributor

@paulmedynski paulmedynski commented May 20, 2026

Summary

Enables InternalsVisibleTo for SqlClient UnitTests across package/project reference modes with an explicit signing policy. This supports the upcoming sqlclient-test pipeline that will use package mode to run all tests. It will also be signing assemblies when it runs in the ADO.Net project - a gap in our current CI pipelines.

Behavior

Signing ReferenceType IVT Granted?
Unsigned Project Yes
Unsigned Package Yes
Signed Package Yes (with PublicKey)
Signed Project No

Changes

  • SqlClient.csproj: Added unsigned IVT (InternalsVisibleTo("UnitTests")) and signed+Package IVT block with test key public key
  • UnitTests.csproj: Removed ValidateReferenceType error target; added conditional ProjectReference/PackageReference with ExcludeAssets="compile" and explicit Reference to the runtime DLL; added TestSigningKeyPath signing
  • TestCommon.csproj: Made SqlClient reference conditional on ReferenceType; added TestSigningKeyPath signing
  • TestUtilities.csproj: Added TestSigningKeyPath signing (prevents CS8002 when referenced by signed tests)
  • TDS projects: Added TestSigningKeyPath signing blocks
  • build.proj: Declared TestSigningKeyPath property and plumbed it into TestSqlClientUnit target

Pipeline Changes

  • run-all-tests-step.yml: Unit test steps now pass -p:ReferenceType, -p:PackageVersionSqlClient, and -p:PackageVersionSqlServer directly (matching the Functional/Manual test pattern) instead of conditionally gating on Project mode

Relates to

AB#45126, AB#45162

Testing

  • PR runs will ensure no regressions in Project mode, and will confirm the new Package mode paths.
  • CI runs will do the same. These never perform assembly signing, so the Package+Signing mode isn't tested here.
  • Package+Signing:
    • I will manually run the new sqlclient-package pipeline (based on this PR) to produce artifacts that are signed and include the new InternalsVisibleTo via public key.
    • Then, I will build, sign, and run the tests locally.
    • We will fully prove these changes out via the forthcoming sqlclient-test pipeline.

Copilot AI review requested due to automatic review settings May 20, 2026 12:04
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board May 20, 2026
@paulmedynski paulmedynski added this to the 7.1.0-preview2 milestone May 20, 2026
@paulmedynski paulmedynski added Area\Tests Issues that are targeted to tests or test projects Area\Engineering Use this for issues that are targeted for changes in the 'eng' folder or build systems. labels May 20, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the build/test infrastructure so test projects can access internals (via InternalsVisibleTo) when running against Package references, including the signed package scenario by introducing a separate test signing key (TestSigningKeyPath) and wiring it through build.proj.

Changes:

  • Add InternalsVisibleTo entries for signed + ReferenceType=Package builds (with an explicit public key) in SqlClient, Abstractions, and Azure projects.
  • Update test projects to conditionally use ProjectReference vs PackageReference based on ReferenceType, and sign test/helper assemblies when TestSigningKeyPath is provided.
  • Plumb TestSigningKeyPath and ReferenceType into build.proj test targets; add a new CI pipeline YAML for packing all packages in Package mode.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj Conditional project/package references; optional test signing to satisfy IVT with signed packages.
src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj Optional signing so signed tests can reference this helper assembly.
src/Microsoft.Data.SqlClient/tests/Common/Microsoft.Data.SqlClient.TestCommon.csproj Conditional SqlClient reference (project vs package) and optional signing for signed-test compatibility.
src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj Add signed+Package IVT (with PublicKey) while keeping unsigned IVT behavior.
src/Microsoft.Data.SqlClient.Extensions/Azure/test/Azure.Test.csproj Conditional project/package reference to Azure extension; optional signing for IVT fulfillment.
src/Microsoft.Data.SqlClient.Extensions/Azure/src/Azure.csproj Add signed+Package IVT entry for Azure tests (with PublicKey).
src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/Abstractions.Test.csproj Conditional project/package reference to Abstractions; optional signing for IVT fulfillment.
src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj Add signed+Package IVT entry for Abstractions tests (with PublicKey).
eng/pipelines/sqlclient-pr-project-ref-pipeline.yml Exclude eng/pipelines/ci/* from PR trigger path filters.
eng/pipelines/sqlclient-pr-package-ref-pipeline.yml Exclude eng/pipelines/ci/* from PR trigger path filters.
eng/pipelines/ci/package/sqlclient-package.yml New CI pipeline to pack all packages using build.proj in ReferenceType=Package mode.
build.proj Add TestSigningKeyPath plumbing and pass reference/signing/package-version args into test targets.

Comment thread build.proj
Comment thread eng/pipelines/ci/package/sqlclient-package.yml Outdated
Comment thread eng/pipelines/ci/package/sqlclient-package.yml Outdated
Comment thread src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj Outdated

<!-- Strong name signing ============================================= -->
<!-- Sign with the test key so signed test assemblies can reference this project. -->
<PropertyGroup Condition="'$(TestSigningKeyPath)' != ''">
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any projects used by a signed test project must also be signed.

Copilot AI review requested due to automatic review settings May 20, 2026 14:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated no new comments.

@paulmedynski paulmedynski force-pushed the dev/paul/internals-package-mode branch from a5332e8 to d038ec5 Compare May 20, 2026 14:43
Copilot AI review requested due to automatic review settings May 20, 2026 15:28
@paulmedynski paulmedynski force-pushed the dev/paul/internals-package-mode branch from d038ec5 to 2a46b0a Compare May 20, 2026 15:28
@paulmedynski paulmedynski force-pushed the dev/paul/internals-package-mode branch from 2a46b0a to 2463f9a Compare May 20, 2026 15:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj
-p:Configuration=${{ parameters.buildConfiguration }}
-p:DotnetPath=${{ parameters.dotnetx86RootPath }}
-p:TestResultsFolderPath=TestResults
- task: DotNetCoreCLI@2
Copy link
Copy Markdown
Contributor Author

@paulmedynski paulmedynski May 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we will see unit test runs in the PR/CI Package mode pipelines. Neither of those perform signing, so InternalsVisibleTo will be granted by the SqlClient project.

There is no new risk here. Apps can already access everything via reflection. If we ever publish unsigned assemblies, we have much bigger problems than IVT.

-->
<ItemGroup Condition="'$(SigningKeyPath)' != '' AND '$(ReferenceType)' == 'Package'">
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>UnitTests, PublicKey=00240000048000001401000006020000002400005253413100080000010001003D19684676DA365F331D00CE7BD4B8EF03E74102F39A5681B40622703D68F0298ECACECC723D3FFC1EA9365AF4958578550EA1EBEEC084B0B3757F3762449F5365E872802A4B548056760764FAD062BFEE81ED26183109AD46810E7E6E965419D0A10473680144D20C1BFE1027A5F586CA987523C06F5C126C44EA7D4F51EB023867A9F294315F95775ACEFD2D678186919458DFCCB4DE2E9F53AEFC766C7CBCEC474ED21C1616E5A9414D366D91D121C39F5FE6641295ADC058EF3FB10593BCDE2E82D9F217C2634909EEF496CD53AE78ABBEA572B871D72EBFC5378205950ABA97C7CCC2B9635D96933D5F9C9624D71FF53EE2094CF3A6BD38534D66E414B7</_Parameter1>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new signing key specifically for tests. It lives in the ADO.Net project as a secure file. This is its public key.

(runtimes/{rid}/lib/{tfm}/), not in the ref assembly (ref/{tfm}/). We exclude the ref
compile asset and reference the runtime DLL directly so the compiler can see internals.

TODO: This is fragile, depending on our SqlClient NuGet package layout and supported TFMs. This
Copy link
Copy Markdown
Contributor Author

@paulmedynski paulmedynski May 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that if/when our other test projects (i.e. Azure.Test) adopt this Package+Signing approach, those projects won't need this foo since they don't produce and package ref assemblies.

Comment thread build.proj
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.95%. Comparing base (b700269) to head (1499698).
⚠️ Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4300      +/-   ##
==========================================
- Coverage   66.04%   65.95%   -0.10%     
==========================================
  Files         275      279       +4     
  Lines       42976    66211   +23235     
==========================================
+ Hits        28383    43667   +15284     
- Misses      14593    22544    +7951     
Flag Coverage Δ
CI-SqlClient ?
PR-SqlClient-Project 65.95% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paulmedynski paulmedynski moved this from To triage to In progress in SqlClient Board May 20, 2026
Base automatically changed from dev/paul/sql-server-project-refs to main May 20, 2026 19:32
Copilot AI review requested due to automatic review settings May 20, 2026 19:37
@paulmedynski paulmedynski force-pushed the dev/paul/internals-package-mode branch from e91096e to fd1a2ff Compare May 20, 2026 19:38
@paulmedynski paulmedynski changed the title Enable InternalsVisibleTo for test projects in Package mode Enable InternalsVisibleTo for UnitTests in Package mode May 20, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment thread build.proj
Comment thread build.proj
@paulmedynski paulmedynski marked this pull request as ready for review May 21, 2026 15:43
@paulmedynski paulmedynski requested a review from a team as a code owner May 21, 2026 15:43
Copilot AI review requested due to automatic review settings May 21, 2026 15:43
@paulmedynski paulmedynski enabled auto-merge (squash) May 21, 2026 15:43
@paulmedynski paulmedynski moved this from In progress to In review in SqlClient Board May 21, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area\Engineering Use this for issues that are targeted for changes in the 'eng' folder or build systems. Area\Tests Issues that are targeted to tests or test projects

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

4 participants