-
Notifications
You must be signed in to change notification settings - Fork 845
Open
Labels
area-telemetrybugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.untriaged
Description
Description
Compilation error when using multi targeting such as .NET 10 and NET 9.0 or NET 8.0 or both of them.
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
Copilot
Metadata
Metadata
Assignees
Labels
area-telemetrybugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.untriaged