Repository navigation
Consumer build-time validation of SqlClient family package versions #4815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b73e480
Validate installed SqlClient family versions from Logging packages
paulmedynski d0449ee
Fix legacy package ID validation and clarify propagation for PR #4815
paulmedynski be4bdd1
Fix #4815 package manifest gating
paulmedynski 693ce51
Fix #4815 detect legacy packages.config style
paulmedynski 70599d0
Fix #4815: warn on SqlClient family version mismatches
paulmedynski f43dc5d
Fix #4815: move family version check into Microsoft.Data.SqlClient
paulmedynski 6a4924c
Fix #4815: clarify consumer version check coverage
paulmedynski 871e889
Fix #4815: keep the version check best-effort on unreadable manifests
paulmedynski 15ae2bb
Merge branch 'main' into dev/paul/aot/phase-1.1
paulmedynski 7910b81
Merge branch 'main' into dev/paul/aot/phase-1.1
paulmedynski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/Microsoft.Data.SqlClient/build/Microsoft.Data.SqlClient.targets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| <!-- | ||
| Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this | ||
| file to you under the MIT license. | ||
| --> | ||
| <Project> | ||
| <!-- Microsoft.Data.SqlClient owns the consumer check and ships it in build/ and buildTransitive/. | ||
| When SqlClient is present in the consuming package graph, it anchors comparisons against | ||
| installed members of the lockstep family. SqlServer.Server and native SNI are independently | ||
| versioned. Project references are not package-version evidence. | ||
|
|
||
| This is a best-effort helper that surfaces mismatches where it can; it is not a guarantee. | ||
| Mixing family package versions is unsupported whether or not this check reports it. | ||
| Limitations: | ||
| - It relies on .NET SDK/NuGet targets and items (ResolvePackageAssets, ResolveReferences, | ||
| and the NuGetPackageId/NuGetPackageVersion metadata). SDKs, project types, or custom | ||
| pipelines that omit them, or run them in another order, silently skip the check. | ||
| - Multi-targeting outer builds do not resolve references; only inner builds are checked. | ||
| - Missing inputs are treated as "nothing to check" rather than guessed. | ||
| It does not raise errors on its own: mismatches are warnings, and failures to read inputs | ||
| (for example a malformed packages.config) are downgraded to MSBuild warnings. Consumers | ||
| that treat warnings as errors still see these as errors. --> | ||
| <PropertyGroup> | ||
| <SqlClientEnforceFamilyVersions Condition="'$(SqlClientEnforceFamilyVersions)' == ''">true</SqlClientEnforceFamilyVersions> | ||
| </PropertyGroup> | ||
|
|
||
| <Target Name="ValidateSqlClientFamilyPackageVersions" | ||
| AfterTargets="ResolvePackageAssets;ResolveReferences" | ||
| Condition="'$(SqlClientEnforceFamilyVersions)' == 'true' And '$(DesignTimeBuild)' != 'true'"> | ||
| <ItemGroup> | ||
| <!-- Collect first, then use qualified metadata so framework/project references without | ||
| NuGet metadata cannot cause MSB4096. Include RID-specific runtime-only assets. --> | ||
| <_SqlClientResolvedAsset Include="@(ResolvedCompileFileDefinitions);@(ReferencePath);@(RuntimeCopyLocalItems);@(RuntimeTargetsCopyLocalItems)" /> | ||
| <_SqlClientFamilyAsset Include="@(_SqlClientResolvedAsset)" | ||
| Condition="'%(_SqlClientResolvedAsset.NuGetPackageId)' == 'Microsoft.Data.SqlClient' Or | ||
| '%(_SqlClientResolvedAsset.NuGetPackageId)' == 'Microsoft.Data.SqlClient.Extensions.Abstractions' Or | ||
| '%(_SqlClientResolvedAsset.NuGetPackageId)' == 'Microsoft.Data.SqlClient.Extensions.Azure' Or | ||
| '%(_SqlClientResolvedAsset.NuGetPackageId)' == 'Microsoft.Data.SqlClient.Internal.Logging' Or | ||
| '%(_SqlClientResolvedAsset.NuGetPackageId)' == 'Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider'"> | ||
| <FamilyVersion>%(_SqlClientResolvedAsset.NuGetPackageVersion)</FamilyVersion> | ||
| <FamilyId>%(_SqlClientResolvedAsset.NuGetPackageId)</FamilyId> | ||
| </_SqlClientFamilyAsset> | ||
| <_SqlClientAnchorVersion Include="@(_SqlClientFamilyAsset)" | ||
| Condition="'%(_SqlClientFamilyAsset.FamilyId)' == 'Microsoft.Data.SqlClient' And '%(_SqlClientFamilyAsset.FamilyVersion)' != ''" /> | ||
| </ItemGroup> | ||
| <PropertyGroup> | ||
| <!-- Compare resolved version strings, including prerelease labels, not ranges or assembly | ||
| versions. Missing package metadata is not assigned a guessed version. --> | ||
| <_SqlClientExpectedFamilyVersion>@(_SqlClientAnchorVersion->'%(FamilyVersion)'->Distinct())</_SqlClientExpectedFamilyVersion> | ||
| </PropertyGroup> | ||
| <Warning Code="SQLCLIENT001" | ||
| Condition="'%(_SqlClientFamilyAsset.FamilyVersion)' != '' And '$(_SqlClientExpectedFamilyVersion)' != '' And '%(_SqlClientFamilyAsset.FamilyVersion)' != '$(_SqlClientExpectedFamilyVersion)'" | ||
| Text="SqlClient family version mismatch: %(_SqlClientFamilyAsset.FamilyId) is %(_SqlClientFamilyAsset.FamilyVersion), but Microsoft.Data.SqlClient is $(_SqlClientExpectedFamilyVersion). Upgrade all installed family packages together, including prerelease labels. Suppress warning: SqlClientEnforceFamilyVersions=false." /> | ||
|
paulmedynski marked this conversation as resolved.
Resolved
|
||
|
|
||
| <!-- Legacy packages.config consumers import build/ explicitly through NuGet installation. | ||
| Read installed versions from the manifest, independently of assembly reference metadata. --> | ||
| <PropertyGroup> | ||
| <!-- Match NuGet: prefer the project-specific manifest, replacing spaces with underscores. --> | ||
| <_SqlClientConfigPath Condition="'$(RestoreProjectStyle)' == 'PackagesConfig' Or | ||
| ('$(RestoreProjectStyle)' == '' And '@(PackageReference)' == '')">$(MSBuildProjectDirectory)/packages.$(MSBuildProjectName.Replace(' ', '_')).config</_SqlClientConfigPath> | ||
| <_SqlClientConfigPath Condition="('$(RestoreProjectStyle)' == 'PackagesConfig' Or | ||
| ('$(RestoreProjectStyle)' == '' And '@(PackageReference)' == '')) And | ||
| !Exists('$(_SqlClientConfigPath)')">$(MSBuildProjectDirectory)/packages.config</_SqlClientConfigPath> | ||
| </PropertyGroup> | ||
| <XmlPeek XmlInputPath="$(_SqlClientConfigPath)" | ||
| Query="/packages/package[translate(@id, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='microsoft.data.sqlclient']/@version" | ||
| Condition="Exists('$(_SqlClientConfigPath)')" | ||
| ContinueOnError="WarnAndContinue"> | ||
| <Output TaskParameter="Result" PropertyName="_SqlClientConfigExpectedVersion" /> | ||
| </XmlPeek> | ||
| <XmlPeek XmlInputPath="$(_SqlClientConfigPath)" | ||
| Query="/packages/package[(translate(@id, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='microsoft.data.sqlclient.internal.logging' or translate(@id, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='microsoft.data.sqlclient.extensions.abstractions' or translate(@id, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='microsoft.data.sqlclient' or translate(@id, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='microsoft.data.sqlclient.extensions.azure' or translate(@id, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='microsoft.data.sqlclient.alwaysencrypted.azurekeyvaultprovider') and @version!='$(_SqlClientConfigExpectedVersion)']" | ||
| Condition="'$(_SqlClientConfigExpectedVersion)' != ''" | ||
| ContinueOnError="WarnAndContinue"> | ||
| <Output TaskParameter="Result" ItemName="_SqlClientConfigMismatch" /> | ||
| </XmlPeek> | ||
| <Warning Code="SQLCLIENT001" | ||
| Condition="'@(_SqlClientConfigMismatch)' != ''" | ||
| Text="SqlClient family version mismatch in $(_SqlClientConfigPath): %(_SqlClientConfigMismatch.Identity), but Microsoft.Data.SqlClient is $(_SqlClientConfigExpectedVersion). Upgrade all installed family packages together, including prerelease labels. Suppress warning: SqlClientEnforceFamilyVersions=false." /> | ||
| </Target> | ||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.