Fix SqlServer sibling reference handling#4259
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates how the repo’s sibling Microsoft.SqlServer.Server dependency is referenced under ReferenceType (Project vs Package), so package-mode builds/restores can resolve consistent versions and projects that require internals can explicitly enforce project-mode.
Changes:
- Switched several test/sample projects from unconditional
Microsoft.SqlServer.Serverpackage references toProjectReference/PackageReferenceconditioned on$(ReferenceType). - Added a unit-test guard to explicitly reject
ReferenceType=Package. - Updated
build.proj/Directory.Packages.propsto flowSqlServerPackageVersionin package mode and to packMicrosoft.SqlServer.Serverinto the local packages feed.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj | Adds Microsoft.SqlServer.Server project reference and rejects ReferenceType=Package. |
| src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/UdtTest/UDTs/Utf8String/Utf8String.csproj | Conditional project/package reference for Microsoft.SqlServer.Server. |
| src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/UdtTest/UDTs/Shapes/Shapes.csproj | Conditional project/package reference for Microsoft.SqlServer.Server. |
| src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/UdtTest/UDTs/Circle/Circle.csproj | Conditional project/package reference for Microsoft.SqlServer.Server (also normalizes file header). |
| src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/UdtTest/UDTs/Address/Address.csproj | Conditional project/package reference for Microsoft.SqlServer.Server (also normalizes file header). |
| src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTests.csproj | Centralizes conditional Microsoft.SqlServer.Server reference for manual tests. |
| src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.csproj | Removes unused Microsoft.SqlServer.Server package reference from ref build project. |
| src/Microsoft.Data.SqlClient/notsupported/Microsoft.Data.SqlClient.csproj | Uses project reference for Microsoft.SqlServer.Server in project mode and package ref in package mode. |
| src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj | Formatting-only tweak to conditional reference items. |
| doc/samples/Microsoft.Data.SqlClient.Samples.csproj | Makes Microsoft.SqlServer.Server a conditional project/package reference based on ReferenceType. |
| Directory.Packages.props | Moves Microsoft.SqlServer.Server version declaration under ReferenceType=Package and uses $(SqlServerPackageVersion). |
| build.proj | Imports Versions.props to set default package versions in package mode; fixes SqlServer version forwarding; packs Microsoft.SqlServer.Server to $(PackagesDir); adds package-mode pack dependencies to build targets. |
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="../../src/Microsoft.SqlServer.Server/Microsoft.SqlServer.Server.csproj" |
There was a problem hiding this comment.
@paulmedynski - Not sure this is necessary. The other siblings are all package refs.
There was a problem hiding this comment.
Yeah, I think the samples should remain package references?
| <PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" /> | ||
| <PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" /> | ||
| <PackageReference Include="Microsoft.SqlServer.Server" /> | ||
| <PackageReference Include="Microsoft.SqlServer.Server" Condition="'$(ReferenceType)' == 'Package'" /> |
There was a problem hiding this comment.
@paulmedynski - Figure out why this project references SqlServer differently than src and ref.
| <!-- Imports ========================================================= --> | ||
| <Import Project="src/Directory.Build.props" /> | ||
|
|
||
| <!-- Import each project's Versions.props to apply default version numbers in Package mode. --> |
There was a problem hiding this comment.
An alternative would be to execute a dotnet build and use the -getProperty option to return the computed version. That is likely the preferred approach.
| instead (see Directory.Packages.props). When running in project mode, the | ||
| parameters. If these are not provided, defaults are evaluated from each | ||
| package's Versions.props and applied via Directory.Packages.props. When | ||
| running in project mode, the |
| <ReferenceTypeArgument Condition="'$(ReferenceType.ToLower())' == 'package'"> | ||
| -p:ReferenceType=Package | ||
| </ReferenceTypeArgument> | ||
|
|
| --> | ||
| <Target Name="BuildSqlClientNotSupported"> | ||
| <PropertyGroup> | ||
| <BuildSqlClientNotSupportedDependsOn Condition="'$(ReferenceType.ToLower())' == 'package'">PackAbstractions</BuildSqlClientNotSupportedDependsOn> |
There was a problem hiding this comment.
@benrr101 - Do we want these Build* and Pack* targets to depend on the Pack targets of the siblings this target depends on?
I think I would like this to work without any previous targets run, and use default package versions:
dotnet build -t:BuildSqlClient -p:ReferenceType=Package
2851620 to
775fa11
Compare
f4fcba7 to
d0492fe
Compare
| </ItemGroup> | ||
|
|
||
| <Target Name="ValidateReferenceType" BeforeTargets="Restore;PrepareForBuild" | ||
| Condition="'$(ReferenceType)' == 'Package'"> |
| For `PackSqlClient`, these additional parameters are required because dependency versions are injected into the SqlClient nuspec during pack: | ||
|
|
||
| - `-p:PackageVersionAbstractions=<version>` | ||
| - `-p:PackageVersionLogging=<version>` | ||
|
|
| We only need other driver package versions specified when building via | ||
| package references. | ||
| --> | ||
| <!-- The driver packages need versions numbers when we build via Package references. --> |
benrr101
left a comment
There was a problem hiding this comment.
Blocking on:
- Package/project reference going in their own item group, as per existing pattern
- Revisiting the intention of including the version props file in build.proj and confusing the recalculation of versions.
| <PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" /> | ||
| <PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" /> | ||
| <PackageReference Include="Microsoft.SqlServer.Server" /> | ||
| <PackageReference Include="Microsoft.SqlServer.Server" Condition="'$(ReferenceType)' == 'Package'" /> |
There was a problem hiding this comment.
Please follow the above pattern above - put both package and project references (like this) in one item group.
| <PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" /> | ||
| <PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" /> | ||
| <PackageReference Include="Microsoft.SqlServer.Server" /> | ||
| <PackageReference Include="Microsoft.SqlServer.Server" Condition="'$(ReferenceType)' == 'Package'" /> |
There was a problem hiding this comment.
Remove this in favor of the package/project reference in a separate item group above
There was a problem hiding this comment.
Nb: I hate these dang little projects.
| <!-- Imports ========================================================= --> | ||
| <Import Project="src/Directory.Build.props" /> | ||
|
|
||
| <!-- Import each project's Versions.props to apply default version numbers in Package mode. --> |
There was a problem hiding this comment.
I don't think this will work as well as you think it will ... The parameters passed to build.proj are PackageVersion* while the parameters passed to the csproj (and props files) are *PackageVersion. This was a compromise between wanting neat and orderly parameters in build2.proj, and not obliterating the existing csproj parameters.
| Example: 1.0.1-dev2345 | ||
| --> | ||
| <PackageVersionAbstractions Condition="'$(PackageVersionAbstractions)' == ''" /> | ||
| <PackageVersionAbstractions Condition="'$(PackageVersionAbstractions)' == ''">$(AbstractionsPackageVersion)</PackageVersionAbstractions> |
There was a problem hiding this comment.
This more or less confound the whole versioning process I laid out...
The intention was that each project would know what its versions should be, and any projects that depend on another project just references that project and gets the sibling version. Further, the intention is that package reference goes away, so the remaining scenario where a package version is needed goes away.
Doing things this way means .... we calculate the versions with only some of the parameters provided, then call dotnet with this version, then recalculate the version with the package version provided. I think it's confusing and I'm not sure what scenario its trying to solve.
| $(ReferenceTypeArgument) | ||
| $(PackageVersionAbstractionsArgument) | ||
| $(PackageVersionLoggingArgument) | ||
| $(PackageVersionSqlServerArgument) |
There was a problem hiding this comment.
This isn't being added as a parameter at the top.
d0492fe to
88d1198
Compare
88d1198 to
8200659
Compare
| <NuspecProperties>$(NuspecProperties);COMMITID=$(CommitId)</NuspecProperties> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- Checkc for empty sibling package versions. --> |
| <PropertyGroup> | ||
| <BuildSqlClientUnixDependsOn Condition="'$(ReferenceType.ToLower())' == 'package'">PackAbstractions;PackLogging;PackSqlServer</BuildSqlClientUnixDependsOn> | ||
| </PropertyGroup> | ||
| <Target Name="BuildSqlClientUnix" DependsOnTargets="$(BuildSqlClientUnixDependsOn)"> |
| <DotnetCommand> | ||
| "$(DotnetPath)dotnet" pack $(SqlServerProjectPath) | ||
| -p:Configuration=$(Configuration) | ||
| -p:PackageOutputPath="$(PackagesDir)" |
| <!-- Reference Type Arguments --> | ||
| $(ReferenceTypeArgument) | ||
| $(PackageVersionAbstractionsArgument) | ||
| $(PackageVersionLoggingArgument) | ||
| $(PackageVersionSqlServerArgument) | ||
| </DotnetCommand> |
Summary
Microsoft.SqlServer.Serversibling references across affected projects to respectReferenceType(Project vs Package)SqlServerPackageVersionwiring through build orchestrationBUILDGUIDE.mdaligned with the current build/pack entrypoint guidanceMicrosoft.Data.SqlClient.csprojValidation
dotnet build src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj -f net8.0 -v minimaldotnet build src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTests.csproj -f net8.0 -v minimaldotnet build build.proj -t:BuildSqlClientUnix -p:ReferenceType=Package -v minimaldotnet build src/Microsoft.Data.SqlClient.slnx -v minimaldotnet build build.proj -p:Configuration=Debug