Skip to content

ref: replace concrete TargetFramework string comparisons with TargetFrameworkIdentifier/Version properties - #5240

Merged
jamescrosswell merged 5 commits into
mainfrom
fix-tfm-conditions
Jul 10, 2026
Merged

jamescrosswell merged 5 commits into
mainfrom
fix-tfm-conditions

Conversation

@jamescrosswell

Copy link
Copy Markdown
Collaborator

Summary

Replace hardcoded $(TargetFramework) string comparisons in .csproj files with the more scalable $(TargetFrameworkIdentifier) + $(TargetFrameworkVersion) property checks, as recommended by MSBuild best practices.

  • '$(TargetFramework)' == 'net8.0' → '$(TargetFrameworkIdentifier)' == '.NETCoreApp' And '$(TargetFrameworkVersion)' == 'v8.0'
  • '$(TargetFramework)' == 'net48' → '$(TargetFrameworkIdentifier)' == '.NETFramework' And '$(TargetFrameworkVersion)' == 'v4.8'
  • '$(TargetFramework)' == 'netstandard2.0' → '$(TargetFrameworkIdentifier)' == '.NETStandard' And '$(TargetFrameworkVersion)' == 'v2.0'
  • $(TargetFramework.Contains('-ios')) → '$(TargetPlatformIdentifier)' == 'ios'

14 files updated across src/, test/, and samples/.

#skip-changelog

Closes #2657

…rameworkIdentifier/TargetFrameworkVersion properties

Replace `$(TargetFramework) == 'net8.0'` style conditions with
`$(TargetFrameworkIdentifier) == '.NETCoreApp' And $(TargetFrameworkVersion) == 'v8.0'`
equivalents across src, test, and samples project files, as recommended by
the MSBuild best practices guidance. Also replaces `TargetFramework.Contains('-ios')`
with `$(TargetPlatformIdentifier) == 'ios'`.

Closes #2657

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Signed-off-by: James Crosswell <[email protected]>
@codecov

codecov Bot commented May 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.21%. Comparing base (a9cb3b2) to head (036db61).
⚠️ Report is 83 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5240      +/-   ##
==========================================
+ Coverage   74.12%   74.21%   +0.09%     
==========================================
  Files         508      509       +1     
  Lines       18282    18386     +104     
  Branches     3574     3600      +26     
==========================================
+ Hits        13551    13645      +94     
- Misses       3861     3867       +6     
- Partials      870      874       +4     

☔ View full report in Codecov by Harness.
📢 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.

A bunch of these were unnecessarily specific, simply because historically it was easier to do an exact match than fuzzy matching. Checking the identifier and the versions separately, we can drop the version checks whenever we're checking for netfx and often times when checking for netstandard as well (e.g. when we only target on version of netstandard).

Co-authored-by: James Crosswell <[email protected]>
@jamescrosswell
jamescrosswell marked this pull request as ready for review May 18, 2026 22:14
@jamescrosswell
jamescrosswell requested a review from Flash0ver as a code owner May 18, 2026 22:14
@jamescrosswell jamescrosswell added the skip-changelog Suppress automatic changelog generation via Craft label May 27, 2026

@Flash0ver Flash0ver left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Found some more potential occurrences we could replace ... and a potential problem.

Comment thread src/Sentry/Sentry.csproj Resolved
Comment thread src/Sentry/Sentry.csproj Resolved
Comment thread src/Sentry/Sentry.csproj Resolved
jamescrosswell and others added 2 commits July 8, 2026 17:49
Extend the TargetFramework -> TargetFrameworkIdentifier/Version conversion to the
remaining conditions raised in review, and make the approach reliable everywhere.

Pre-compute TargetFrameworkIdentifier/TargetFrameworkVersion in Directory.Build.props
(exactly as the SDK does, including the 'v' version prefix). The SDK only sets these
late in its own targets, so they were empty during early <PropertyGroup> evaluation -
computing them early lets us use the property-based syntax consistently in both
<PropertyGroup> and <ItemGroup> conditions instead of $(TargetFramework) string checks.

Also:
- Convert the remaining net4/netstandard/net48 conditions across src, test and samples.
- Drop incidental .NET Framework version pins; the specific version was never required.
- Simplify the native-AOT upload gate to the existing $(_SentryIsNet8OrGreater) helper,
  which also correctly excludes net5/6/7 (the previous list missed net5).
- Remove the dead RS0017 NoWarn (the analyzer that emitted it was removed in #1313).
- Use a clearer negated form for the Serilog netstandard2.0 package condition.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Jul 8, 2026
@jamescrosswell
jamescrosswell requested a review from Flash0ver July 8, 2026 07:46

@Flash0ver Flash0ver left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What a changeset ... contender for the most inclusions of ".NET" 😉

I got one final question:

The root Directory.Build.props already computes TargetPlatformIdentifier early
(before the project body), and this project imports it, so the local recompute in the
arm64 RuntimeIdentifier group was a no-op reassignment of the same value.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@jamescrosswell
jamescrosswell merged commit 373e860 into main Jul 10, 2026
51 checks passed
@jamescrosswell
jamescrosswell deleted the fix-tfm-conditions branch July 10, 2026 01:48
jamescrosswell added a commit that referenced this pull request Nov 24, 2026
…nd debug file upload for Android Native AOT builds (#6002)

* fix(msbuild): Upload Android Native AOT debug files from bin/

The Android workload sets _IsPublishing on every Native AOT build, so Android
apps matched the desktop Native AOT upload settings whenever the version flags
were set, for example with -f or in a multi-targeted MAUI app. Those settings
upload from PublishDir after _CopyAotSymbols or Publish, so a plain build never
ran the upload. On net11, a publish didn't help either, because publish/ holds
only the APK and AAB there and sentry-cli found no debug files.

Android is now excluded from those settings, like iOS and Mac Catalyst. It
takes the managed path, which uploads from OutputPath after Build. By then
native/ already holds the debug file, lib<app>.dbg.so on net11 and
<app>.so.dbg on net10. A new cli-maui case builds a single-target Android
Native AOT app and checks that the debug file gets uploaded.

Refs #5744

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(msbuild): Read TargetFramework directly in Sentry.targets

The Native AOT upload settings and SetAndroidNdkPreload read the
_SentryIsNet*OrGreater flags, which Sentry.props sets only when TargetFramework
has a value. NuGet imports Sentry.props before the project body, and a
single-target project sets TargetFramework in that body, so the flags stayed
empty unless -f passed TargetFramework as a global property. The Native AOT
check compared TargetFramework directly until #5240.

As a result, a Native AOT publish fell back to the managed upload, which sends
the managed PDBs from bin/ instead of the native debug files from publish/.
SetAndroidNdkPreload skipped the io.sentry.ndk.preload metadata for Android
apps that don't run on Mono.

Sentry.targets now checks TargetFramework with IsTargetFrameworkCompatible
where it needs a version. NuGet imports it after the project body, where
TargetFramework has its value. The flags compared only the version number, so
monoandroid90 counted as net9. IsTargetFrameworkCompatible checks the framework
too. Nothing reads the net10 and net11 flags any more, so Sentry.props drops
them.

Every integration test that uploads symbols passed --framework, so none of them
caught this. The Native AOT "uploads symbols" test now publishes without it,
through a new -OmitFrameworkArgument switch on RunDotnetWithSentryCLI, and
checks that the upload comes from publish/. The cli-maui Android Native AOT case
now builds without --framework too and checks the manifest for the preload
metadata.

Fixes #5744

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ref(msbuild): Keep the net10 and net11 flags in Sentry.props

Sentry.targets no longer reads _SentryIsNet10OrGreater or
_SentryIsNet11OrGreater, but Sentry.props ships in the package, so a project
outside the SDK might read them. Removing them would give that project an
empty value with no warning.

Refs #5744

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ref(msbuild): Update the notes that link the two Native AOT checks

The notes said the target framework conditions in Sentry.targets and
Sentry.Native.targets are kept the same. Sentry.targets now uses
IsTargetFrameworkCompatible and Sentry.Native.targets still uses its own
version flags, so what the two share is the net8.0 minimum. The note in
Sentry.Native.targets also pointed at a buildTransitive/Sentry.Native.targets
that doesn't exist, instead of Sentry.targets.

Refs #5744

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ref(msbuild): Remove the unused net10 and net11 flags from Sentry.props

Nothing reads _SentryIsNet10OrGreater or _SentryIsNet11OrGreater any more.
The underscore marks them as internal, and in a single-target project they
are empty anyway, so keeping them for outside readers bought nothing.

This reverts commit 24a4b80.

Refs #5744

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: James Crosswell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium skip-changelog Suppress automatic changelog generation via Craft

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove references to specific target frameworks from csproj files

2 participants