runtime: PublishReadyToRun fails on .NET6 / linux-musl-x64 / Docker

Description

I’m trying to build using PublishReadyToRun with net6.0 in Docker (mcr.microsoft.com/dotnet/sdk:6.0-alpine) on linux-musl-x64 and getting this error:

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.

My Docker file look like this:

FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build

COPY . .

RUN dotnet restore -r linux-musl-x64

RUN dotnet publish --framework net6.0 -c release -o /app -r linux-musl-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true

FROM mcr.microsoft.com/dotnet/runtime-deps:6.0-alpine-amd64
WORKDIR /app
COPY --from=build /app ./

ENTRYPOINT ["./MyProgram"]

Using this exact Docker file with net5.0 instead works without any issues.

Reproduction Steps

Build a C# project using this Docker:

FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build

COPY . .

RUN dotnet restore -r linux-musl-x64

RUN dotnet publish --framework net6.0 -c release -o /app -r linux-musl-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true

Notice that it fails with the error listed above.

Expected behavior

Since it was building fine in net5.0 I would expect net6.0 to be able to build it as well.

Actual behavior

It fails with:

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.

Regression?

Yes this is a regression, it works perfectly in net5.0

Known Workarounds

It seems like I can build just fine using windows (not Docker) instead but I haven’t tried running the actual output but it did compiled without any error.

Configuration

  • Which version of .NET is the code running on?

net6.0

  • What OS and version, and what distro if applicable?

linux-musl-x64

  • What is the architecture (x64, x86, ARM, ARM64)?

x64

  • Do you know whether it is specific to that configuration?

Seems like I can compile just fine from windows to linux-musl-x64 but building using Docker using mcr.microsoft.com/dotnet/sdk:6.0-alpine or mcr.microsoft.com/dotnet/sdk:6.0 fails.

Other information

No response

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 3
  • Comments: 17 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Yup, this is a regression from .NET 5 SDK, and I agree that error message is not helpful. There are three ways to overcome it:

  1. dotnet publish without --no-restore (this is workaround’ish)
  2. persist <PublishReadyToRun>true</PublishReadyToRun> and <PublishTrimmed>true</PublishTrimmed> properties in csproj and continue to use dotnet restore and dotnet publish --no-restore (this is more sustainable, I think)
  3. dotnet restore -p:PublishReadyToRun=true -p:PublishTrimmed=true then donet publish --no-restore -p:PublishTrimmed=true -p:PublishReadyToRun=true ... (i.e. do not change project properties between restore and publish)

Just a reminder that this is still a problem with NET 7 preview 3.

At this point I’m evaluating disabling ReadyToRun for my application.

Yup, this is a regression from .NET 5 SDK, and I agree that error message is not helpful. There are three ways to overcome it:

  1. persist <PublishReadyToRun>true</PublishReadyToRun> and <PublishTrimmed>true</PublishTrimmed> properties in csproj and continue to use dotnet restore and dotnet publish --no-restore (this is more sustainable, I think)

Solution number 2 works well ✅. Thank you @am11!

Thank you very much! Yes that did work!

Still feels like a regression since it is impossible to specify to dotnet restore that I want it to restore with PublishReadyToRun so I can’t have a distinct layer in my docker for restore (my docker file was trimmed down in the issue, I actually first copy only the *.csproj, do a dotnet restore then copy the rest of the files and finally do the dotnet publish --no-restore).

The error message is a bit misleading as well, makes it sounds like the platform cannot compile with PublishReadyToRun when in fact some files were not downloaded.