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
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
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.
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.