Enable InternalsVisibleTo for UnitTests in Package mode#4300
Conversation
There was a problem hiding this comment.
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
InternalsVisibleToentries for signed +ReferenceType=Packagebuilds (with an explicit public key) in SqlClient, Abstractions, and Azure projects. - Update test projects to conditionally use
ProjectReferencevsPackageReferencebased onReferenceType, and sign test/helper assemblies whenTestSigningKeyPathis provided. - Plumb
TestSigningKeyPathandReferenceTypeintobuild.projtest 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. |
ccfa6f8 to
52e7d4b
Compare
a5332e8 to
d038ec5
Compare
d038ec5 to
2a46b0a
Compare
2a46b0a to
2463f9a
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
e91096e to
fd1a2ff
Compare
mdaigle
left a comment
There was a problem hiding this comment.
If we take this approach, we'll still need to maintain the project build style. Community contributors won't have access to the private key.
Looking at these changes, I think enabling unit testing for package build is a good idea - and since it only applies to signed and verified packages, we are protected by signing key. So yes, it's not for contributors or customers, we are enabling use specifically for our testing needs, and that's a secure approach. |
Summary
Enables
InternalsVisibleTofor SqlClientUnitTestsacross package/project reference modes with an explicit signing policy. This supports the upcomingsqlclient-testpipeline 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
Changes
InternalsVisibleTo("UnitTests")) and signed+Package IVT block with test key public keyValidateReferenceTypeerror target; added conditional ProjectReference/PackageReference withExcludeAssets="compile"and explicit Reference to the runtime DLL; addedTestSigningKeyPathsigningTestSigningKeyPathsigningTestSigningKeyPathsigning (prevents CS8002 when referenced by signed tests)TestSigningKeyPathsigning blocksTestSigningKeyPathproperty and plumbed it intoTestSqlClientUnittargetPipeline Changes
-p:ReferenceType,-p:PackageVersionSqlClient, and-p:PackageVersionSqlServerdirectly (matching the Functional/Manual test pattern) instead of conditionally gating on Project modeRelates to
AB#45126, AB#45162
Testing
InternalsVisibleTovia public key.