Skip to content

Build error NETSDK1124 with NET8 RC2 when multiple TargetFrameworks #94406

@snakefoot

Description

@snakefoot

Description

Trying to publish an application <TargetFramework>net8.0</TargetFramework> with trimming enabled:

dotnet publish -r win-x64 -c release --self-contained -p:PublishTrimmed=true .\examples\NetCore2\HostingExample

The application depends on two libraries:

  • NLog.Extensions.Logging:
    <TargetFrameworks>net461;netstandard1.3;netstandard1.5;netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks>
    
  • NLog.Extensions.Hosting:
    <TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks>
    

The build fails with the following error:

C:\Program Files\dotnet\sdk\8.0.100-rc.2.23502.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceRes
olution.targets(90,5): error NETSDK1124: Trimming assemblies requires .NET Core 3.0 or higher. [C:\Users\snakefoot\sour
ce\repos\NLog.Extensions.Logging\src\NLog.Extensions.Hosting\NLog.Extensions.Hosting.csproj::TargetFramework=netstandar
d2.0]
C:\Program Files\dotnet\sdk\8.0.100-rc.2.23502.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceRes
olution.targets(90,5): error NETSDK1124: Trimming assemblies requires .NET Core 3.0 or higher. [C:\Users\snakefoot\sour
ce\repos\NLog.Extensions.Logging\src\NLog.Extensions.Logging\NLog.Extensions.Logging.csproj::TargetFramework=net461]

Reproduction Steps

Publish NET8 application with trimming, that depends on projects with mutiple <TargetFrameworks> (Besides NET8)

Also tried to update library-projects to be very explicit about when to enable trimming, but build with publish still fails (No warnings or errors with standard dotnet build):

    <EnableTrimAnalyzer Condition=" '$(TargetFramework)' == 'net8.0'">true</EnableTrimAnalyzer>
    <IsTrimmable Condition=" '$(TargetFramework)' == 'net8.0'">true</IsTrimmable>

Also tried adding these command-line options -f net8.0 or -p:TargetFramework=net8.0, but the build-error remains.

Expected behavior

Build publishes the application without errors.

Actual behavior

Build fails with error NETSDK1124: Trimming assemblies requires .NET Core 3.0 or higher. for the library projects.

Regression?

Build publish with trimming works fine with NET6 + NET7

Known Workarounds

Uninstall NET8 RC2 SDK or stop using multiple TargetFrameworks in library-projects or depend on nuget-packages instead of the library-projects directly.

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Tools-ILLink.NET linker development as well as trimming analyzers

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions