ReadyToRun publishing fails in 6.0 due to NETSDK1095
See original GitHub issueWhen 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:
- Created 2 years ago
- Comments:11 (11 by maintainers)
Top GitHub Comments
since cg2 is now a separate package
PublishReadyToRun
needs to be passed to restore:RUN dotnet restore -r linux-x64 /p:PublishReadyToRun=true
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.”