question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReadyToRun publishing fails in 6.0 due to NETSDK1095

See original GitHub issue

When attempting to publish a .NET project with R2R, it fails with the following error: /usr/share/dotnet/sdk/6.0.100-preview.7.21379.14/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Publish.targets(293,5): error NETSDK1095: Optimizing assemblies for performance is not supported for the selected target platform or architecture. Please verify you are using a supported runtime identifier, or set the PublishReadyToRun property to false. [/app/app.csproj]

This is a regression from 5.0.

The conditions in which this occur require that a dotnet restore command be run before executing dotnet publish and executing publish w/o a restore. This can be easily demonstrated in a Docker environment with the following example Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim-amd64 AS build
WORKDIR /app

RUN dotnet new console
RUN dotnet restore -r linux-x64
RUN dotnet publish -c release -o /out -r linux-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true

If you were to remove the --no-restore option from the last line, the publish would succeed.

In comparison, this Dockerfile using 5.0 can be built successfully:

FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim-amd64 AS build
WORKDIR /app

RUN dotnet new console
RUN dotnet restore -r linux-x64
RUN dotnet publish -c release -o /out -r linux-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true

It is essentially the same as the 6.0 Dockerfile but instead uses the 5.0 SDK.

The issue is also not limited to Linux. It can be reproduced in Windows environments as this Dockerfile demonstrates:

FROM mcr.microsoft.com/dotnet/sdk:6.0-nanoserver-20H2 AS build
WORKDIR /app

RUN dotnet new console
RUN dotnet restore -r win-x64
RUN dotnet publish -c release -o /out -r win-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true

Attempting to build this Dockerfile will produce the same error: C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(293,5): error NETSDK1095: Optimizing assemblies for performance is not supported for the selected target platform or architecture. Please verify you are using a supported runtime identifier, or set the PublishReadyToRun property to false. [C:\app\app.csproj]

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
mangod9commented, Sep 9, 2021

since cg2 is now a separate package PublishReadyToRun needs to be passed to restore:

RUN dotnet restore -r linux-x64 /p:PublishReadyToRun=true

0reactions
AntonLapounovcommented, Mar 14, 2022

We have improved the error message with words “When targeting .NET 6 or higher, make sure to restore packages with the PublishReadyToRun property set to true.”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Publish ReadyToRun with --no-restore requires changes
In .NET 6, dotnet restore followed by dotnet publish -p:PublishReadyToRun=true --no-restore will fail with the NETSDK1095 error.
Read more >
Building .NET Core AWS Lambda with ReadyToRun on ...
error NETSDK1095 : Optimizing assemblies for performance is not supported for the selected target platform or architecture.
Read more >
Publishing a DevExpress application results in the " ...
The error message implies that ReadyToRun images were trying to be generated for the published application. I might be mistaken, but ReadyToRun ......
Read more >
error NETSDK1031: It is not supported to build or publish a ...
I am running following command to publish .NET CORE 5.0 web api project using command line on windows 10 box. c:\test\Service>dotnet publish -c ......
Read more >
Untitled
Issues 2.3k. ... NET 6 Azure Web App Deployment using Azure DevOps Pipelines . ... ReadyToRun publishing fails in 6.0 due to NETSDK1095...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found