Skip to content

Enable setting RID for dotnet restore with -a and --os #51667

@richlander

Description

@richlander

I thought we had enabled this earlier, but apparently not. This would make it easier and more efficient to produce platform-specific assets in platform-agnostic Dockerfiles.

I removed --no-restore and that works. It's not ideal. The other option is to set the RID directly, but that is a worse solution given that the goal is platform agnostic Dockerfile and project file. For example, caching works much better with --no-restore.

ich@merritt:~/git/dotnet-docker/samples/globalapp$ docker build --pull -t globalapp .
[+] Building 0.7s (12/14)                                                                              docker:default
=> [internal] load build definition from Dockerfile                                                             0.0s
=> => transferring dockerfile: 639B                                                                             0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/runtime-deps:10.0                                      0.1s
=> [internal] load metadata for mcr.microsoft.com/dotnet/sdk:10.0                                               0.1s
=> [internal] load .dockerignore                                                                                0.0s
=> => transferring context: 2B                                                                                  0.0s
=> [build 1/6] FROM mcr.microsoft.com/dotnet/sdk:10.0@sha256:c7445f141c04f1a6b454181bd098dcfa606c61ba0bd213d0a  0.0s
=> [stage-1 1/3] FROM mcr.microsoft.com/dotnet/runtime-deps:10.0@sha256:69ee6d1a1b7a92cc82a71001342554d4611a50  0.0s
=> [internal] load build context                                                                                0.0s
=> => transferring context: 869B                                                                                0.0s
=> CACHED [build 2/6] WORKDIR /source                                                                           0.0s
=> CACHED [build 3/6] COPY --link *.csproj .                                                                    0.0s
=> CACHED [build 4/6] RUN dotnet restore -a amd64 --os linux                                                    0.0s
=> CACHED [build 5/6] COPY --link . .                                                                           0.0s
=> ERROR [build 6/6] RUN dotnet publish -a amd64 --no-restore -o /app                                           0.5s
------                                                                                                                
> [build 6/6] RUN dotnet publish -a amd64 --no-restore -o /app:                                                      
0.484 /usr/share/dotnet/sdk/10.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(544,5): error NETSDK1112: The runtime pack for Microsoft.NETCore.App.Runtime.linux-x64 was not downloaded. Try running a NuGet restore with the RuntimeIdentifier 'linux-x64'. [/source/globalapp.csproj]
------
Dockerfile:13
--------------------
  11 |     # Copy source code and publish app
  12 |     COPY --link . .
  13 | >>> RUN dotnet publish -a $TARGETARCH --no-restore -o /app
  14 |     
  15 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c dotnet publish -a $TARGETARCH --no-restore -o /app" did not complete successfully: exit code: 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    untriagedRequest triage from a team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions