Skip to content
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

Regression - NET8 Preview1 SDK won't publish trimmed self contained solution with netstandard2.1 projects #30948

Closed
michaldobrodenka opened this issue Mar 1, 2023 · 4 comments · Fixed by dotnet/docs#36775
Assignees
Milestone

Comments

@michaldobrodenka
Copy link

I have project with reference to netstandard2.1 class libraries. When I try to publish it, it ends up in error:

error NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Mar 1, 2023
@0xced
Copy link

0xced commented Jun 19, 2023

I stumbled on the same issue when trying to add .NET 8 support in Serilog.

Here is a simple reproduction.

Issue30948.csproj:

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

  <PropertyGroup>
    <TargetFrameworks>netstandard2.1;net461;net8.0</TargetFrameworks>
    <IsTrimmable>true</IsTrimmable>
  </PropertyGroup>

</Project>
dotnet build
MSBuild version 17.7.0-preview-23281-03+4ce2ff1f8 for .NET
  Determining projects to restore...
C:\Program Files\dotnet\sdk\8.0.100-preview.5.23303.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5): error NETSDK1195: Unable to optimize assemblies for size: a valid run time package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. [C:\Projects\Experiments\Issue30948\Issue30948.csproj]

Build FAILED.

Does it mean that IsTrimmable should be set to false when targeting .NET Standard 2.1 in a class library?

@agocke agocke added Area-ILLink and removed untriaged Request triage from a team member Area-NetSDK labels Jul 8, 2023
@ghost
Copy link

ghost commented Jul 8, 2023

@dotnet/illink-contrib a new issue has been filed in the ILLink area, please triage

@agocke agocke assigned sbomer and unassigned dsplaisted Jul 8, 2023
@agocke agocke added this to the .NET 8.0 milestone Jul 8, 2023
@sbomer
Copy link
Member

sbomer commented Aug 9, 2023

Closing this as expected since trimming isn't a supported scenario for netstandard2.1 libraries - see dotnet/runtime#86924. Note that the warning message has improved, so you should now get:

sdk/8.0.100-rc.1.23404.1/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5): warning NETSDK1195: IsTrimmable is not supported for the target framework. Consider multi-targeting to a supported framework to enable trimming, and set IsTrimmable only for the supported frameworks. For example: [netstandard-lib.csproj]
sdk/8.0.100-rc.1.23404.1/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5): warning NETSDK1195: <IsTrimmable Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</IsTrimmable> [netstandard-lib.csproj]
sdk/8.0.100-rc.1.23404.1/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5): warning NETSDK1195: For more information, see https://aka.ms/netsdk1195 [netstandard-lib.csproj]

The recommendation is to multi-target the library to at least net6.0 instead, and avoid setting IsTrimmable for the unsupported TFMs.

@sbomer sbomer closed this as completed Aug 9, 2023
@sbomer
Copy link
Member

sbomer commented Aug 9, 2023

Re-opening this to track adding a breaking change notice about the new warning.

@sbomer sbomer reopened this Aug 9, 2023
jonathanpeppers added a commit to jonathanpeppers/maui that referenced this issue Aug 16, 2023
Context: dotnet/sdk#30948

Building with VS 2022 17.8 Preview 1, I get the error:

    C:\Program Files\dotnet\sdk\8.0.100-preview.7.23376.3\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5):
    error NETSDK1195: Trimming, or code compatibility analysis for trimming, single-file deployment, or ahead-of-time compilation is not supported for the target framework. For more information, see https://aka.ms/netsdk1195

It appears there is a new build warning if you set `IsTrimmable=true` in
a `netstandard` project.

For now, this doesn't really matter to MAUI as these projects only
*really* need to be trimmable for mobilie. `net8.0-android`,
`net8.0-ios`, etc. projects can remain trimmable if we add a condition:

    <IsTrimmable Condition="!$(TargetFramework.StartsWith('netstandard'))">true</IsTrimmable>
rmarinho pushed a commit to dotnet/maui that referenced this issue Aug 17, 2023
Context: dotnet/sdk#30948

Building with VS 2022 17.8 Preview 1, I get the error:

    C:\Program Files\dotnet\sdk\8.0.100-preview.7.23376.3\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5):
    error NETSDK1195: Trimming, or code compatibility analysis for trimming, single-file deployment, or ahead-of-time compilation is not supported for the target framework. For more information, see https://aka.ms/netsdk1195

It appears there is a new build warning if you set `IsTrimmable=true` in
a `netstandard` project.

For now, this doesn't really matter to MAUI as these projects only
*really* need to be trimmable for mobilie. `net8.0-android`,
`net8.0-ios`, etc. projects can remain trimmable if we add a condition:

    <IsTrimmable Condition="!$(TargetFramework.StartsWith('netstandard'))">true</IsTrimmable>
rmarinho pushed a commit to dotnet/maui that referenced this issue Aug 19, 2023
Context: dotnet/sdk#30948

Building with VS 2022 17.8 Preview 1, I get the error:

    C:\Program Files\dotnet\sdk\8.0.100-preview.7.23376.3\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5):
    error NETSDK1195: Trimming, or code compatibility analysis for trimming, single-file deployment, or ahead-of-time compilation is not supported for the target framework. For more information, see https://aka.ms/netsdk1195

It appears there is a new build warning if you set `IsTrimmable=true` in
a `netstandard` project.

For now, this doesn't really matter to MAUI as these projects only
*really* need to be trimmable for mobilie. `net8.0-android`,
`net8.0-ios`, etc. projects can remain trimmable if we add a condition:

    <IsTrimmable Condition="!$(TargetFramework.StartsWith('netstandard'))">true</IsTrimmable>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants