Skip to content

[7.1.0-preview1] Fix TFM Attributes#4254

Merged
paulmedynski merged 2 commits into
mainfrom
dev/russellben/tfm-assembly-attributes
May 1, 2026
Merged

[7.1.0-preview1] Fix TFM Attributes#4254
paulmedynski merged 2 commits into
mainfrom
dev/russellben/tfm-assembly-attributes

Conversation

@benrr101
Copy link
Copy Markdown
Contributor

@benrr101 benrr101 commented May 1, 2026

Investigation and fix was done via 🤖 Here's it's explanation of the issue and the proposed solution:


We investigated the TFM mismatch seen in the Microsoft.Data.SqlClient release artifacts and package. The short version is that this does not look like a nuspec bug or an ESRP signing bug.

What we verified:

  • The package layout is correct. net8.0, net9.0, and net462 assets are being pulled from their expected build-output folders.
  • The signed build-output DLLs and the DLLs inside the package match byte-for-byte, so packaging is not copying the wrong binaries.
  • The binaries are not all the same assembly. Their hashes, sizes, and framework references differ as expected.
  • However, several final artifacts have the wrong managed TargetFrameworkAttribute embedded in metadata. For example, some net9.0 and net462 outputs report .NETCoreApp,Version=v8.0 even though their actual assembly references still line up with the correct target.

We traced this to a recent release-only build change in src/Directory.Build.props. Specifically, when BuildForRelease=true, we override
TargetFrameworkMonikerAssemblyAttributesPath. In the normal build path, that property resolves to separate per-TFM files like:

  • obj/Release/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs
  • obj/Release/net9.0/.NETCoreApp,Version=v9.0.AssemblyAttributes.cs
  • obj/Release/net462/.NETFramework,Version=v4.6.2.AssemblyAttributes.cs

With BuildForRelease=true, it instead collapses to a shared path:

  • .AssemblyAttributes

That means multiple target frameworks can reuse/overwrite the same generated assembly-attributes file, which explains how the final binaries can end up with the wrong TargetFrameworkAttribute while still otherwise being the correct target-specific build.

Recommendation:
I would not treat this as safe to ignore, even for a preview release. It is probably not catastrophic for NuGet asset selection or normal runtime behavior, because the actual binaries and references appear correct. But it is still a real release-quality issue:

  • tools and reflection can observe the wrong target framework
  • net462 especially reporting .NETCoreApp metadata is bad and confusing
  • we have an identified likely root cause in the repo, not just a tooling glitch

My recommendation is to fix this before release if at all possible. The likely fix is to remove or move that TargetFrameworkMonikerAssemblyAttributesPath override so it is evaluated later, after per-target intermediate paths are established. If schedule pressure is extreme, I would at minimum block on a quick validation build after changing that override, because this looks like a deterministic regression introduced by the release-only build path rather than a benign display issue.


Ben again, I don't even think we need this file at all, but I do not have the bandwidth at the moment to validate it will still report as deterministic if I just delete it. But the 🤖 says this is safer, so we can go with it for now.

@benrr101 benrr101 added this to the 7.1.0-preview1 milestone May 1, 2026
@benrr101 benrr101 requested a review from a team as a code owner May 1, 2026 01:46
Copilot AI review requested due to automatic review settings May 1, 2026 01:46
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board May 1, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a release-build regression where multi-target builds could embed an incorrect TargetFrameworkAttribute by removing the BuildForRelease=true override that collapsed TargetFrameworkMonikerAssemblyAttributesPath to a shared path.

Changes:

  • Remove the TargetFrameworkMonikerAssemblyAttributesPath override from src/Directory.Build.props for BuildForRelease=true builds.
  • Update the repo solution (.slnx) to include a Directory.Build.targets entry under /src/.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Microsoft.Data.SqlClient.slnx Adds Directory.Build.targets to the solution items under /src/.
src/Directory.Build.props Removes the release-only override that could cause cross-TFM overwrites of generated assembly-attribute files.

Comment thread src/Microsoft.Data.SqlClient.slnx Outdated
Comment thread src/Directory.Build.props Outdated
Copy link
Copy Markdown
Member

@cheenamalhotra cheenamalhotra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Contributor

@paulmedynski paulmedynski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TFM removal looks good. Not sure what the targets file in the solution is for, but it won't hold this PR up.

Comment thread src/Microsoft.Data.SqlClient.slnx
@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.23%. Comparing base (7a01dbe) to head (f9a18c5).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4254      +/-   ##
==========================================
- Coverage   66.02%   64.23%   -1.79%     
==========================================
  Files         277      272       -5     
  Lines       42988    65783   +22795     
==========================================
+ Hits        28382    42257   +13875     
- Misses      14606    23526    +8920     
Flag Coverage Δ
CI-SqlClient ?
PR-SqlClient-Project 64.23% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paulmedynski paulmedynski moved this from To triage to In review in SqlClient Board May 1, 2026
@paulmedynski paulmedynski added the Area\Engineering Use this for issues that are targeted for changes in the 'eng' folder or build systems. label May 1, 2026
@paulmedynski paulmedynski merged commit 1129387 into main May 1, 2026
303 checks passed
@paulmedynski paulmedynski deleted the dev/russellben/tfm-assembly-attributes branch May 1, 2026 12:33
@github-project-automation github-project-automation Bot moved this from In review to Done in SqlClient Board May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area\Engineering Use this for issues that are targeted for changes in the 'eng' folder or build systems.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants