Aspnetcore.docs: Explanation for copy steps in Dockerfile template

Created on 18 Jul 2019  Â·  6Comments  Â·  Source: dotnet/AspNetCore.Docs

From @AbdoHassanUMG ...

Why the project file is copied individually before dotnet restore then a "COPY . . " statement is execute later ?

What's the benefit of doing a csproj copy instead of doing a "COPY . ." before the dotnet restore?

Docs tag 5847cdf8-1823-7740-6e43-030902b26ad8

@UsmanMohammad


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

P1 Source - Docs.ms doc-enhancement

Most helpful comment

In case it’s helpful, I answered this exact question on Stack Overflow a few months ago: https://stackoverflow.com/questions/53460002/how-to-use-dotnet-restore-properly-in-dockerfile/54832279#54832279.

All 6 comments

In case it’s helpful, I answered this exact question on Stack Overflow a few months ago: https://stackoverflow.com/questions/53460002/how-to-use-dotnet-restore-properly-in-dockerfile/54832279#54832279.

Brilliant ! very smart optimisation
Thanks @serpent5

What happens when there are Directory.Build.props/targets and Custom SDKs involved, and the project files are in different folders with a distinct directory structure?

You can't do this

# copy csproj and restore as distinct layers
COPY *.sln .
COPY aspnetapp/*.csproj ./aspnetapp/
RUN dotnet restore

The COPY command will not mirror the directory structure, which most bigger solutions and projects are composed of.

RELATED: moby/moby#39530

It may work for samples and templates (_with no directory structure_), but not real world projects.

Moved to #16250

@serpent5 should we add your SO post info to this doc?

@Rick-Anderson I just realised I didn't respond to this one. I've opened up a PR for it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Rick-Anderson picture Rick-Anderson  Â·  3Comments

madelson picture madelson  Â·  3Comments

StevenTCramer picture StevenTCramer  Â·  3Comments

davisnw picture davisnw  Â·  3Comments

AnthonyMastrean picture AnthonyMastrean  Â·  3Comments