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
Project builds fine in Docker
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.
$ 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
This seems to me like something wrong in your dockerfile (I don't know what) and not some inherent issue with the SDK and the build.
@MichaelSimons can you help us here?
@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
...
@MichaelSimons thanks, this was indeed due to .dockerignore
With yours it works fine, with mine (below) it was failing:
obj
.vscode
.vs
.git
I haven't found any recommendations as to why folders should have **
prefix - eg https://github.com/dotnet/dotnet-docker-samples/blob/master/dotnetapp-dev/.dockerignore doesn't do that - do you happen to know the reason for **
or should I open a question elsewhere?
@andreister - please refer to Docker's documentation on the .dockerignore file
I am going to close this issue as it seems to be addressed and to be outside of the CLI.
Most helpful comment
@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.