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.

dotnet paket restore failed while building docker image

See original GitHub issue

Description

The command “dotnet paket restore” exited with code 1.

Repro steps

Please provide the steps required to reproduce the problem

  1. Install paket as .Net core Local tool POCs\HelloDI> dotnet new tool-manifest POCs\HelloDI> dotnet tool install paket POCs\HelloDI> dotnet paket init

  2. add /bin & /obj to .dockerignore file at root folder

.git
**/bin/
**/obj/
  1. add package to .csproject POCs\HelloDI> cd .\src\HelloDI.Console\ POCs\HelloDI\src\HelloDI.Console> dotnet paket add Microsoft.Extensions.Configuration.Json --interactive

  2. Docker file contents (src\HelloDI.Console\Dockerfile)

ARG VERSION=3.1-alpine3.12
FROM mcr.microsoft.com/dotnet/core/sdk:$VERSION as build-env
WORKDIR /HelloDI.Console

COPY /src/HelloDI.Console/*.csproj .
RUN dotnet restore

COPY . .
RUN dotnet publish src/HelloDI.Console/HelloDI.Console.csproj --output /out/ --configuration Release

FROM mcr.microsoft.com/dotnet/core/runtime:$VERSION as runtime
WORKDIR /HelloDI.Console
COPY --from=build-env /out .

ENTRYPOINT ["dotnet", "HelloDI.Console.dll"]
  1. Local Msbuild successful. POCs\HelloDI\src\HelloDI.Console> cd ..\.. POCs\HelloDI> dotnet build

Output

Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Paket version 5.247.4
  The last restore is still up to date. Nothing left to do.
  Performance:
   - Runtime: 228 milliseconds
  Paket version 5.247.4
  Starting restore process.
  Performance:
   - Runtime: 1 second
  Restored D:\@aviWin10.workspace\@POCs\HelloDI\tests\HelloDI.Console.Tests\HelloDI.Console.Tests.csproj (in 9.3 sec).
  1 of 2 projects are up-to-date for restore.

.....
  1. Error during-Build Docker image POCs\HelloDI> docker build -t hello-di/console:0.1 -f ./src/HelloDI.Console/dockerfile .

Output

Step 5/11 : RUN dotnet restore
 ---> Using cache
 ---> a3b73898202f
Step 6/11 : COPY . .
 ---> 65085b0c2d6f
Step 7/11 : RUN dotnet publish src/HelloDI.Console/HelloDI.Console.csproj --output /out/ --configuration Release
 ---> Running in f16be0b6c474
Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Run "dotnet tool restore" to make the "paket" command available.
/HelloDI.Console/.paket/Paket.Restore.targets(171,5): error MSB3073: The command "dotnet paket restore" exited with code 1. 
[/HelloDI.Console/src/HelloDI.Console/HelloDI.Console.csproj]
The command '/bin/sh -c dotnet publish src/HelloDI.Console/HelloDI.Console.csproj --output /out/ --configuration Release' returned a non-zero code: 1

Expected behavior

dotnet paket restore should execute successfully.

Actual behavior

error at dotnet paket restore

Known workarounds

remove **/obj/ from .dockerignore

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
ramondekleincommented, Nov 11, 2020

I encountered the same issue and it seems that during build-time it explicitly invokes dotnet-paket instead of dotnet paket. I created a symlink in my Dockerfile to ensure that the file can be run. My Dockerfile looks like this:

FROM mcr.microsoft.com/dotnet/sdk:5.0
WORKDIR /app

# Make sure we have enough to restore all packages
COPY paket.dependencies paket.lock .config/dotnet-tools.json ./
RUN dotnet tool restore
RUN echo "#!/bin/sh" > /usr/local/bin/dotnet-paket && echo "dotnet `find /root/.nuget/packages/paket -name paket.dll` \$*" >> /usr/local/bin/dotnet-paket && chmod 755 /usr/local/bin/dotnet-paket
RUN dotnet paket restore

# Copy source code
COPY . ./

# Pubish output
RUN dotnet publish -c Release --framework net5.0 --runtime linux-x64 -o /out/x64 MyAmazingProject/MyAmazingProject.csproj

The important line is the RUN echo ... to create the dotnet-paket command. I am not a big fan of using find, because it may result in multiple binaries. I did use it to not break my Dockerfile when I upgrade paket.

0reactions
im-avicommented, Jul 24, 2020

This is a problem with your docker file.

You need to run dotnet tool restore to ensure that the paket tool is installed for your repository before paket an be used to restore your dependencies.

Alternatively, since you’ve restored already in your dockerfile you can pass the --no-restore flag to dotnet publish to skip restoring at all, which should not trigger paket.

Just tried above suggestion : As I am trying to containerize a single project from multi-project solution

  1. Updated docker file
ARG VERSION=3.1-alpine3.12
FROM mcr.microsoft.com/dotnet/core/sdk:$VERSION as build-env
WORKDIR /HelloDI

COPY /.config/dotnet-tools.json .config/dotnet-tools.json
RUN dotnet tool restore

COPY HelloDI.sln .
COPY paket.dependencies .
COPY paket.lock .
COPY src/HelloDI.Console/HelloDI.Console.csproj src/HelloDI.Console/HelloDI.Console.csproj
COPY src/HelloDI.Console/paket.references src/HelloDI.Console/paket.references
RUN dotnet restore src/HelloDI.Console/HelloDI.Console.csproj

COPY . .

RUN dotnet publish src/HelloDI.Console/HelloDI.Console.csproj --output /out/ --configuration Release --no-restore


FROM mcr.microsoft.com/dotnet/core/runtime:$VERSION as runtime
WORKDIR /HelloDI.Console
COPY --from=build-env /out .


ENTRYPOINT ["dotnet", "HelloDI.Console.dll"]
  1. Build docker image POCs\HelloDI> docker build -t hello-di/console:0.1 -f ./src/HelloDI.Console/dockerfile .

Expected behavior

  • Output should be Successfully tagged hello-di/console:0.1

Actual behavior

  • Error while publishing
Step 13/17 : RUN dotnet publish src/HelloDI.Console/HelloDI.Console.csproj --output /out/ --configuration Release --no-restore
 ---> Running in e3337125a4cc
Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Paket version 5.247.4
  The last restore is still up to date. Nothing left to do.
  Performance:
   - Runtime: 221 milliseconds
  Paket version 5.247.4
  Starting restore process.
  Downloading Microsoft.Extensions.Configuration 3.1.6
  Downloading Microsoft.Extensions.Configuration.FileExtensions 3.1.6
  Downloading Microsoft.Extensions.FileProviders.Abstractions 3.1.6
  Downloading Microsoft.Extensions.FileSystemGlobbing 3.1.6
  Downloading Microsoft.Extensions.Primitives 3.1.6
  Download of Microsoft.Extensions.Configuration 3.1.6 done in 2 seconds. (171 kbit/s, 0 MB)
  Download of Microsoft.Extensions.Primitives 3.1.6 done in 2 seconds. (205 kbit/s, 0 MB)
  Download of Microsoft.Extensions.FileSystemGlobbing 3.1.6 done in 2 seconds. (136 kbit/s, 0 MB)
  Downloading Microsoft.Extensions.Configuration.Abstractions 3.1.6
  Download of Microsoft.Extensions.Configuration.FileExtensions 3.1.6 done in 3 seconds. (140 kbit/s, 0 MB)
  Downloading Microsoft.Extensions.Configuration.Json 3.1.6
  Download of Microsoft.Extensions.Configuration.Abstractions 3.1.6 done in 417 milliseconds. (1045 kbit/s, 0 MB)
  Download of Microsoft.Extensions.FileProviders.Abstractions 3.1.6 done in 4 seconds. (93 kbit/s, 0 MB)
  Downloading Microsoft.Extensions.FileProviders.Physical 3.1.6
  Download of Microsoft.Extensions.Configuration.Json 3.1.6 done in 1 second. (355 kbit/s, 0 MB)
  Download of Microsoft.Extensions.FileProviders.Physical 3.1.6 done in 1 second. (466 kbit/s, 0 MB)
  Performance:
   - Disk IO: 92 milliseconds
   - Average Download Time: 209 milliseconds
   - Number of downloads: 8
   - Average Request Time: 393 milliseconds
   - Number of Requests: 12
   - Runtime: 6 seconds
/usr/share/dotnet/sdk/3.1.302/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1004: Assets file '/HelloDI/src/HelloDI.Console/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/HelloDI/src/HelloDI.Console/HelloDI.Console.csproj]
The command '/bin/sh -c dotnet publish src/HelloDI.Console/HelloDI.Console.csproj --output /out/ --configuration Release --no-restore' returned a non-zero code: 1
  • dotnet publish unable to locate file -/HelloDI/src/HelloDI.Console/obj/project.assets.json even though it is generated by previously executed dotnet restore.(verified the file existence by logging into container using docker run -it)

Known workarounds

  • remove option --no-restore from dotnet publish command in above dockerfile. RUN dotnet publish src/HelloDI.Console/HelloDI.Console.csproj --output /out/ --configuration Release –no-restore
  • restore executes twice but there is no fetch from network.
Read more comments on GitHub >

github_iconTop Results From Across the Web

asp.net core - dotnet restore fails from Docker container
I was able to get around this issue by setting the http_proxy in my Dockerfile. ARG HTTP_PROXY="http://username:password@proxy.example.com:8080".
Read more >
Dotnet restore fails when building in docker container
When doing docker restore --disable-parallel it works without any problems, but takes 20 minutes to build that small project.
Read more >
Solving flaky dotnet restore issue only on Docker
When I build a Dockerfile, at the part of the dotnet restore I encountered this issue. However, On my colleague's PC, it works...
Read more >
NuGet restore failing in Docker Container
The Problem. We have a very simple .Net Core MVC solution. It has the following NuGet packages.
Read more >
Rider Dockerfile Build fails with NU1301 and does not restore ...
So when I execute docker build -f Dapr101.Backend/Dockerfile -t dapr101backend --rm everything works. However, still from within Rider build ...
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