-
Notifications
You must be signed in to change notification settings - Fork 845
Fix CS0757 error when multi-targeting with Microsoft.Extensions.Telemetry.Abstractions #7062
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: evgenyfedorov2 <[email protected]>
…gging.Abstractions Co-authored-by: evgenyfedorov2 <[email protected]>
...metry.Abstractions/buildTransitive/net10.0/Microsoft.Extensions.Telemetry.Abstractions.props
Show resolved
Hide resolved
...emetry.Abstractions/buildTransitive/net9.0/Microsoft.Extensions.Telemetry.Abstractions.props
Outdated
Show resolved
Hide resolved
The net8.0 buildTransitive folder is automatically selected by NuGet for net9.0 and net10.0 through nearest compatible framework selection. Only the target name fix was needed. Co-authored-by: evgenyfedorov2 <[email protected]>
Instead of TFM-specific folders (net6.0, net8.0, net9.0, net10.0), use generic buildTransitive files that apply to all target frameworks. This prevents the issue where NuGet's framework selection doesn't automatically apply net8.0 files to net9.0. - Moved buildTransitive files to root of buildTransitive folder (no TFM subfolder) - Disabled automatic TFM-specific buildTransitive generation via DisableNETStandardCompatErrors - Updated packaging to only include root-level buildTransitive files Co-authored-by: evgenyfedorov2 <[email protected]>
|
@copilot good that you removed net8.0 folder, but what about net6.0 folder? |
...crosoft.Extensions.Telemetry.Abstractions/Microsoft.Extensions.Telemetry.Abstractions.csproj
Show resolved
Hide resolved
The net6.0 folder was also removed in commit 25054c3. The files from net6.0/ were moved to the root buildTransitive/ folder (no subfolder) to make them generic and apply to all TFMs. The package now only contains:
No TFM-specific subfolders remain (no net6.0, net8.0, net9.0, or net10.0). |
|
@copilot are you available? |
Yes, I'm available. All the review feedback has been addressed and the fix is complete. The solution uses generic buildTransitive files that apply to all TFMs, and the
... I don't have the ability to squash commits, merge branches, or perform git rebase operations. These actions require direct git commands that I'm not authorized to execute. You'll need to:
The PR is already published at this point with the fix implemented. All review feedback has been addressed and the solution is working correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes CS0757 compilation errors when using Microsoft.Extensions.Telemetry.Abstractions in multi-targeting projects (e.g., targeting both net9.0 and net10.0). The error occurred because MSBuild targets in both Microsoft.Extensions.Logging.Abstractions and Microsoft.Extensions.Telemetry.Abstractions had identical names, causing the Telemetry.Abstractions targets to be overridden and preventing proper removal of duplicate source generators.
Key Changes:
- Renamed MSBuild targets from
_Microsoft_Extensions_Logging_AbstractionsRemoveAnalyzers*to_Microsoft_Extensions_Telemetry_AbstractionsRemoveAnalyzers*to prevent name collision - Switched from TFM-specific buildTransitive files (net8.0/) to generic buildTransitive files that apply to all target frameworks
- Added
DisableNETStandardCompatErrors=trueto prevent automatic TFM-specific buildTransitive folder generation
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/buildTransitive/net8.0/Microsoft.Extensions.Telemetry.Abstractions.targets | Deleted TFM-specific targets file in favor of generic approach |
| src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/buildTransitive/net8.0/Microsoft.Extensions.Telemetry.Abstractions.props | Deleted TFM-specific props file in favor of generic approach |
| src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/buildTransitive/Microsoft.Extensions.Telemetry.Abstractions.targets | Created generic targets file with renamed targets to avoid collision |
| src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/buildTransitive/Microsoft.Extensions.Telemetry.Abstractions.props | Created generic props file that applies to all target frameworks |
| src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Microsoft.Extensions.Telemetry.Abstractions.csproj | Updated packaging configuration to use generic buildTransitive files and disable automatic TFM-specific generation |
|
@joperezr could you review this, please? |
Multi-targeting projects using
Microsoft.Extensions.Telemetry.Abstractionswith net9.0 or net10.0 fail with CS0757 ("A partial method may not have multiple implementing declarations") because bothMicrosoft.Gen.LoggingandMicrosoft.Extensions.Logging.Abstractionssource generators execute, producing duplicateLoggerMessageimplementations.Root Cause
Target name collision: MSBuild target
_Microsoft_Extensions_Logging_AbstractionsRemoveAnalyzersin Telemetry.Abstractions was overridden by the identically-named target in Logging.Abstractions, preventing removal of framework pack analyzers.Changes
_Microsoft_Extensions_Telemetry_AbstractionsRemoveAnalyzers*to prevent name collision with Logging.Abstractions targetsDisableNETStandardCompatErrorsHow It Works
Generic buildTransitive files placed directly in the
buildTransitive/folder (without TFM subfolders) are automatically applied by NuGet to all target frameworks. This ensures consistent behavior across net6.0, net8.0, net9.0, net10.0, and future versions without requiring per-TFM file duplication.The renamed targets now execute properly and remove both:
Reproduction
Fails before fix with CS0757, succeeds after.
Fixes #7061
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Microsoft Reviewers: Open in CodeFlow