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 build --no-restore fails in Docker

See original GitHub issue

Steps to reproduce

Create a .NET Core 2.1 console app:

|-Dockerfile
|-Example1.csproj
|-Example1.sln
|-Program.cs

In Dockerfile restore packages as a first step, and the build with --no-restore as a second step:

FROM microsoft/dotnet:2.1-sdk
WORKDIR /app

# create build image: (restore as distinct layer to speed up build, so we can use --no-restore below)
COPY ./Example1.sln ./
COPY ./*.csproj ./
RUN dotnet restore 

# copy source code and build
COPY ./ ./
RUN dotnet build -c Release -o out --no-restore

Expected behavior

Project builds fine in Docker

Actual behavior

Build fails complaining about missing project.assets.json (notice /app/C:/Users/andrew/ in the path)

/usr/share/dotnet/sdk/2.1.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1004: Assets file '/app/C:/Users/andrew/source/repos/Example1/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/app/Example1.csproj]

Build FAILED.

Environment data

$ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.1.403
 Commit:    04e15494b6

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.403\

Host (useful for support):
  Version: 2.1.5
  Commit:  290303f510

.NET Core SDKs installed:
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.403 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
MichaelSimonscommented, Nov 12, 2018

@andreister, Can you provide a concrete set of steps that can be used to reproduce this issue? Is the directory you are using as you Docker context clean? Make sure you don’t have anything that is getting copied into the Docker image (via COPY ./ ./) that is causing this behavior. You may need to define a .dockerignore file to exclude these.

**/bin
**/obj
**/.vscode
**/.vs
...
1reaction
MichaelSimonscommented, Nov 14, 2018

@andreister - please refer to Docker’s documentation on the .dockerignore file

Read more comments on GitHub >

github_iconTop Results From Across the Web

asp.net core - dotnet restore fails from Docker container
The actual error seems to be: Unable to load the service index for source https://api.nuget.org/v3/index.json.
Read more >
Dotnet restore fails when building in docker container
I set up a docker container in order to build a C# project in it. When performing docker restore , when it tries...
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 >
Docker build caching for .NET applications done right with ...
When the docker build command builds an image, it uses a built-in cache. If the *.csproj files haven't changed since the docker build...
Read more >
Dotnet MSBuild fails in docker when source generated file ...
When I build and run the solution in visual studio everything works fine but when I build it through docker it is failing...
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