Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 20, 2025

Multi-targeting projects using Microsoft.Extensions.Telemetry.Abstractions with net9.0 or net10.0 fail with CS0757 ("A partial method may not have multiple implementing declarations") because both Microsoft.Gen.Logging and Microsoft.Extensions.Logging.Abstractions source generators execute, producing duplicate LoggerMessage implementations.

Root Cause

Target name collision: MSBuild target _Microsoft_Extensions_Logging_AbstractionsRemoveAnalyzers in Telemetry.Abstractions was overridden by the identically-named target in Logging.Abstractions, preventing removal of framework pack analyzers.

Changes

  • Renamed targets to _Microsoft_Extensions_Telemetry_AbstractionsRemoveAnalyzers* to prevent name collision with Logging.Abstractions targets
  • Added net9.0 buildTransitive folder to properly support net9.0 multi-targeting scenarios
  • Maintained TFM-specific buildTransitive folders (net6.0, net8.0, net9.0) to avoid conflicts with SDK's netstandard compat error generation
  • Preserved _AdditionalNETStandardCompatErrorFileContents for net462 compatibility

How It Works

The renamed targets now execute properly without being overridden by Logging.Abstractions targets and remove both:

  • The Microsoft.Extensions.Logging.Abstractions NuGet package analyzer
  • The Microsoft.AspNetCore.App framework pack analyzer

Framework-specific buildTransitive folders ensure proper NuGet package resolution for each target framework without interference from SDK-generated compatibility files.

Reproduction

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>net9.0;net10.0</TargetFrameworks>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Telemetry.Abstractions" Version="10.0.0" />
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>
</Project>
internal static partial class Log
{
    [LoggerMessage(LogLevel.Information, "Hello {Name}")]
    internal static partial void Hello(ILogger logger, string name);
}

Fails before fix with CS0757, succeeds after.

Original prompt

This section details on the original issue you should resolve

<issue_title>Compilation error when using Microsoft.Extensions.Telemetry.Abstractions with multiple TFMs</issue_title>
<issue_description>### Description

Compilation error when using multi targeting such as .NET 10 and NET 9.0 or NET 8.0 or both of them.

Image

Reproduction Steps

csproj file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net9.0;net10.0</TargetFrameworks>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
	  <OutputType>Exe</OutputType>
  </PropertyGroup>

	<ItemGroup>
		<PackageReference Include="Microsoft.Extensions.Telemetry.Abstractions" Version="10.0.0" />
		<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.0" />
		<FrameworkReference Include="Microsoft.AspNetCore.App" />
	</ItemGroup>
</Project>

Program.cs:

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Logging;

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();
app.MapGet("/index", () =>
{
    using var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
    var logger = loggerFactory.CreateLogger("repro");

    Log.Hello(logger, "hi");
});

app.Run();


internal static partial class Log
{
    [LoggerMessage(LogLevel.Information, "Hello {Name}.")]
    internal static partial void Hello(ILogger logger, string name);
}

Expected behavior

Microsoft.Extensions.Logging.Abstractions does not kick in, code compiles and works correctly

Actual behavior

Compilation error CS0757 A partial method may not have multiple implementing declarations

Regression?

No response

Known Workarounds

Add this to csproj file:

	<Target Name="RemoveLoggingAnalyzers" BeforeTargets="CoreCompile">
		<ItemGroup>
			<Analyzer Remove="@(Analyzer)" Condition="'%(Analyzer.AssemblyName)' == 'Microsoft.Extensions.Logging.Generators' Or '%(Analyzer.NuGetPackageId)' == 'Microsoft.Extensions.Logging.Abstractions'" />
		</ItemGroup>
	</Target>

Configuration

.NET 10 and multi targeting build with previous .NET such as 8.0 and/or 9.0

Other information

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ 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

Copilot AI changed the title [WIP] Fix compilation error with Microsoft.Extensions.Telemetry.Abstractions Fix CS0757 error when multi-targeting with Microsoft.Extensions.Telemetry.Abstractions Nov 20, 2025
Copilot AI requested a review from evgenyfedorov2 November 20, 2025 18:28
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]>
@evgenyfedorov2
Copy link
Member

@copilot good that you removed net8.0 folder, but what about net6.0 folder?

Copy link
Contributor Author

Copilot AI commented Nov 21, 2025

@copilot good that you removed net8.0 folder, but what about net6.0 folder?

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:

  • buildTransitive/Microsoft.Extensions.Telemetry.Abstractions.props
  • buildTransitive/Microsoft.Extensions.Telemetry.Abstractions.targets

No TFM-specific subfolders remain (no net6.0, net8.0, net9.0, or net10.0).

@evgenyfedorov2
Copy link
Member

evgenyfedorov2 commented Nov 21, 2025

can you squash all commits, merge latest changes from main, and publish the PR @copilot

@copilot ???

@evgenyfedorov2
Copy link
Member

@copilot are you available?

@evgenyfedorov2 evgenyfedorov2 marked this pull request as ready for review November 21, 2025 14:57
Copilot AI review requested due to automatic review settings November 21, 2025 14:57
@evgenyfedorov2 evgenyfedorov2 requested a review from a team as a code owner November 21, 2025 14:57
Copy link
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

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=true to 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

@evgenyfedorov2
Copy link
Member

@joperezr could you review this, please?

@joperezr
Copy link
Member

joperezr commented Dec 2, 2025

We can't move this file as it will get overridden by the netstandard compat errors one.


Refers to: src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/buildTransitive/Microsoft.Extensions.Telemetry.Abstractions.props:2 in a00b32e. [](commit_id = a00b32e, deletion_comment = False)

@evgenyfedorov2
Copy link
Member

@copilot please return back framework specific buildTransitive files and folders, please also add one for net9.0

- Reverted from generic buildTransitive files to TFM-specific folders (net6.0, net8.0, net9.0)
- Restored _AdditionalNETStandardCompatErrorFileContents for net462 compatibility
- Kept renamed targets (_Microsoft_Extensions_Telemetry_AbstractionsRemoveAnalyzers) to prevent collision
- This addresses feedback that generic buildTransitive files get overridden by netstandard compat errors

Co-authored-by: evgenyfedorov2 <[email protected]>
Copy link
Contributor Author

Copilot AI commented Dec 12, 2025

@copilot please return back framework specific buildTransitive files and folders, please also add one for net9.0

Done in d864ca3. Restored framework-specific buildTransitive folders (net6.0, net8.0) and added net9.0 as requested. Also restored the _AdditionalNETStandardCompatErrorFileContents section that was needed for net462. The renamed targets are kept to prevent the name collision issue.

@evgenyfedorov2
Copy link
Member

@copilot please check if the bug has been fixed with these changes.

Copy link
Contributor Author

Copilot AI commented Dec 12, 2025

@copilot please check if the bug has been fixed with these changes.

Yes, the bug has been fixed. Verified with comprehensive testing:

Multi-targeting test (net9.0 + net10.0): Build succeeded with 0 errors
Extended test (net8.0 + net9.0 + net10.0): All frameworks build successfully
Unit tests: All 56 tests pass on net8.0, net9.0, and net10.0 (168/168 total)

The fix works by:

  • Renaming MSBuild targets to prevent collision with Logging.Abstractions
  • Adding net9.0 buildTransitive folder for proper net9.0 support
  • Maintaining TFM-specific folders to avoid SDK conflicts

No CS0757 errors occur when multi-targeting with Microsoft.Extensions.Telemetry.Abstractions.

@evgenyfedorov2
Copy link
Member

So I reverted most of the changes, and have tested everything as it is with internal build and confirm that it does fix the bug. @joperezr could you please review again?

Copy link
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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

@@ -0,0 +1,6 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

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

The XML declaration is missing from this props file. The net6.0 and net8.0 versions both include the declaration. For consistency across all TFM-specific props files, this file should start with the same XML declaration.

Suggested change
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compilation error when using Microsoft.Extensions.Telemetry.Abstractions with multiple TFMs

4 participants