Enable InternalsVisibleTo for UnitTests in Package mode#4300
Enable InternalsVisibleTo for UnitTests in Package mode#4300paulmedynski wants to merge 4 commits into
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
|
|
||
| <!-- Strong name signing ============================================= --> | ||
| <!-- Sign with the test key so signed test assemblies can reference this project. --> | ||
| <PropertyGroup Condition="'$(TestSigningKeyPath)' != ''"> |
There was a problem hiding this comment.
Any projects used by a signed test project must also be signed.
a5332e8 to
d038ec5
Compare
d038ec5 to
2a46b0a
Compare
2a46b0a to
2463f9a
Compare
| -p:Configuration=${{ parameters.buildConfiguration }} | ||
| -p:DotnetPath=${{ parameters.dotnetx86RootPath }} | ||
| -p:TestResultsFolderPath=TestResults | ||
| - task: DotNetCoreCLI@2 |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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
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.