Repository navigation
Description
Is your feature request related to a problem? Please describe.
SqlClient's packaging currently depends on separately maintained public API declarations, a reference assembly project, a generated unsupported-platform assembly project, and a hand-authored nuspec. This duplicates the implementation's API surface, adds build orchestration, and allows the contract and implementation to drift, as documented in #4826.
We want to simplify this to one packable SqlClient project and normal SDK-generated packaging while preserving all three package targets: net462, netstandard2.0, and net10.0.
The netstandard2.0 asset is a compile-time bridge for intermediate libraries. Those libraries ultimately run in an application targeting a concrete supported framework, which must resolve the real net462 or net10.0 implementation. Retaining this bridge does not imply a full .NET Standard runtime implementation.
Describe the solution you'd like
Intended package layout
lib/net462/Microsoft.Data.SqlClient.dll # Real implementation
lib/netstandard2.0/Microsoft.Data.SqlClient.dll # Generated contract/stub assembly
lib/net10.0/Microsoft.Data.SqlClient.dll # Real implementation
Include the appropriate XML documentation and localized satellite assemblies. Retain the package readme, icon, existing consumer family-version checks under build/ and buildTransitive/, and separate .snupkg symbols packaging. No managed assemblies should be shipped under ref/ or runtimes/.
Native SNI packages remain dependencies and retain their native runtime assets.
Proposed implementation plan
-
Prototype build-time Standard contract generation from the implementation.
- Do not maintain a second set of API declaration source files or a handwritten API allowlist.
- Prefer investigating source-based generation using the implementation's framework-dependent declarations; compare with assembly-based generation using GenAPI or an equivalent tool before committing to the approach.
- Generate source only under the intermediate output directory, not in source control.
- Produce Standard-compatible declarations with explicit
PlatformNotSupportedExceptionfallback behavior rather than a real Standard driver implementation. - Preserve public/protected signatures, generic constraints, constants, relevant attributes, and type forwards. Reuse existing type-forward sources where appropriate.
- Handle framework-specific API shapes explicitly. For example, the modern
SqlBatchderives fromDbBatch, which is not available in .NET Standard 2.0. Blindly generating declarations from the .NET 10 assembly is insufficient. - Audit conditional compilation: compiling source with neither
NETnorNETFRAMEWORKdefined does not by itself guarantee the intended Standard API surface. - Fail generation when declarations cannot be represented faithfully; do not silently omit APIs.
-
Make the implementation project the single packable SqlClient project.
- Target
net462;netstandard2.0;net10.0. - Compile existing implementation sources for the concrete targets and generated contract sources for Standard.
- Update the AKV provider's Project-mode reference from the reference project to the unified SqlClient project, preserving its Standard target and the intermediate-library scenario.
- Target
-
Replace the authored nuspec with normal SDK packaging.
- Move package metadata and explicit non-binary pack items into project properties/items.
- Remove custom nuspec token expansion, generated intermediate nuspec handling, and dependency suppression.
- Generate dependency groups from project/package references while preserving intended bounded sibling version ranges, compile exclusions, and transitive build-asset behavior in both Project and Package reference modes.
- Review differences between current project references and authored nuspec dependencies rather than accidentally changing the consumer graph.
- Remove the source nuspec. SDK pack will still generate the normal package manifest.
-
Remove obsolete projects and simplify orchestration.
- Remove separate ref/notsupported projects, duplicate declarations, solution entries, and build targets.
- Remove GenAPI tooling only if the selected generation approach and remaining repository uses no longer need it.
- Build the implementation once in ordinary build/pack flows.
- Preserve release build -> binary signing ->
pack --no-buildordering without rebuilding or modifying signed outputs.
-
Replace safeguards that currently depend on the reference project.
- Compare generated Standard contracts and concrete implementation public APIs against appropriate baselines, including signatures, attributes, and type forwards.
- Support historical baselines containing
ref/and future baselines containing onlylib/. - Update XML documentation validation and remove the separate reference-documentation pipeline step.
- Decide and document the IntelliSense XML policy: today
ref/has trimmed XML whilelib/has full documentation. Preserve full documentation for the API docs pipeline and explicitly account for any IntelliSense presentation change. - Update build orchestration tests, build documentation, and public API contribution guidance.
Acceptance criteria
- SqlClient exposes
net462,netstandard2.0, andnet10.0assets underlib/only, with no packagedref/assemblies or managed RID-specific assemblies. - The Standard contract is generated from the implementation during a clean build; no separately maintained API declarations are required.
- Generated Standard APIs are compared with the existing Standard contract during migration and checked for compatibility with the concrete implementations.
- A
netstandard2.0intermediate library consuming the package builds and runs through both anet462app and anet10.0app, with the appropriate real implementation selected. - The AKV provider builds and tests successfully in both Project and Package modes without retargeting solely because the reference project was removed.
- Standard stub fallback behavior is explicit, including a deliberate policy for static initialization/fields such as
SqlClientFactory.Instance(see Raise exception on callingSqlClientFactory.Instancefrom facade assembly #4081). - SDK-generated dependency groups/ranges and package contents are verified in both reference modes.
- Windows .NET Framework and Windows/Linux/macOS .NET 10 package consumers are validated, including RID-less builds, RID-specific publishing, native SNI resolution, and direct
lib/loading with required dependencies available. - Clean and incremental builds and signed
pack --no-buildflows work without stale generation or signed-binary replacement. - Documentation, localization, symbols, and API compatibility gates remain effective.
Describe alternatives you've considered
- Keep handwritten reference declarations: preserves duplicate maintenance and API-drift risk; does not meet the goal.
- Retain separate ref/notsupported projects: can preserve current behavior but does not simplify the build as intended.
- Generate from a concrete implementation assembly: potentially reuses existing GenAPI infrastructure, but requires framework-shape transformations and careful build ordering. Evaluate against source-based generation in the prototype.
- Implement the complete driver for .NET Standard 2.0: substantially larger compatibility/porting effort and unnecessary for the compile-time bridge requirement.
- Remove the Standard target or retarget all intermediate libraries: explicitly out of scope; Standard targeting must remain.
Additional context
Related open issues:
- Replace platform-specific builds with runtime OS selection #4239 - Replace platform-specific builds with runtime OS selection. This effort follows its managed
lib/<tfm>layout simplification while retaining the Standard bridge. ref/assemblies do not match implementation assembly API surfaces #4826 -ref/assemblies do not match implementation assembly API surfaces. Generating the contract from implementation should remove the duplicate-maintenance root cause, with compatibility checks retained.- Raise exception on calling
SqlClientFactory.Instancefrom facade assembly #4081 - Raise exception on callingSqlClientFactory.Instancefrom facade assembly. Relevant to explicit, predictable behavior when the generated Standard stub is loaded instead of a concrete implementation.
This issue tracks the broader follow-up: generated Standard contracts, removal of separate ref/notsupported projects, and replacement of the authored nuspec with normal SDK packaging. The generation strategy requires a proof of concept before the detailed implementation is finalized.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsBacklog
Activity
edwardneal commentedon Oct 29, 2026
Interesting! I'd previously been planning to leave the
ref/assemblies in situ with a throw helper, then removing thenotsupportedassembly and GenAPI infrastructure. The netstandard2.0 assemblies would have resulted from normal compilation of theref/assemblies, and ApiCompat would have ensured that the netcore and netfx assemblies aligned with the implementation assemblies. netstandard2.0 was always going to be a weak spot there - it just doesn't have an implementation assembly to test alignment with.The only hard blocker preventing the removal of the
ref/assemblies is, as you've noted, that theref/assemblies have the trimmed XML documentation and the implementation ones do not. If the documentation pipeline can get its data from somewhere else, we could build the package layout as described simply by using the existingref/assembly to target netstandard2.0.API compatibility checking can work using ApiCompat. #4890 only uses assembly validation mode, but with workflow changes it could be switched to package validation mode and act as a safeguard between versions.
A source generator would work to generate the netstandard2.0 assembly, but I think it might be worth trying to use
Microsoft.DotNet.GenAPI.Taskwith relevant API exclusions to generate the source first. This is the modern version of the existing in-tree GenAPI tool. It isn't available on NuGet, but seems to come from one of the package sources here. These are all first-party sources, so hopefully they wouldn't present too many obstacles from that angle.No matter what though, I'd strongly advocate against continuing to use the current in-tree version of GenAPI. I've found in the last few weeks that it mangles the public API slightly: it doesn't faithfully reproduce the
unmanagedgeneric constraint, which means thatSqlVector's type definition is slightly different. I'd expect this mangling to become more prevalent as the language shifts.