Background on my issue. I am trying to build a docker image for a dotnet core api that has a library attached to the solution referenced inside the api.When i run the docker build command I get the warning below and then build errors because it cannot reference the library.
Skipping project "/MyDotnetCoreLib/MyDotnetCoreLib.csproj" because it was not found.
My Dockerfile
FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build-env
WORKDIR /app
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/core/aspnet:2.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "MyAPI.dll"]
My file structure is as below:
--Edit
Error:
Sending build context to Docker daemon 1.426MB
Step 1/10 : FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build-env
---> bf77a711b92c
Step 2/10 : WORKDIR /app
---> Using cache
---> ae6b78cbf588
Step 3/10 : COPY src/Accounts.NT/Accounts.NT.csproj ./
COPY failed: stat /var/lib/docker/tmp/docker-builder190366239/src/Accounts.NT/Accounts.NT.csproj: no such file or directory
PS C:\Git\Personal\Accounts.NT\src\Accounts.NT> docker build -t vumanimdabe/accounts-nt:v1.0 .
Sending build context to Docker daemon 1.426MB
Step 1/10 : FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build-env
---> bf77a711b92c
Step 2/10 : WORKDIR /app
---> Using cache
---> ae6b78cbf588
Step 3/10 : COPY Accounts.NT.csproj ./
---> Using cache
---> b360913be4a4
Step 4/10 : RUN dotnet restore
---> Using cache
---> e9bf7172e851
Step 5/10 : COPY . ./
---> d4f088d6d737
Step 6/10 : RUN dotnet publish -c Release -o out
---> Running in fb8fad58131c
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Skipping project "/Accounts.Data/Accounts.Data.csproj" because it was not found.
Skipping project "/Accounts.Data/Accounts.Data.csproj" because it was not found.
Restore completed in 879.4 ms for /app/Accounts.NT.csproj.
/usr/share/dotnet/sdk/2.1.802/Microsoft.Common.CurrentVersion.targets(1875,5): warning : The referenced project '../Accounts.Data/Accounts.Data.csproj' does not exist. [/app/Accounts.NT.csproj]
Controllers/AccountsController.cs(7,16): error CS0234: The type or namespace name 'Data' does not exist in the namespace 'Accounts' (are you missing an assembly reference?) [/app/Accounts.NT.csproj]
Startup.cs(6,16): error CS0234: The type or namespace name 'Data' does not exist in the namespace 'Accounts' (are you missing an assembly reference?) [/app/Accounts.NT.csproj]
Startup.cs(7,16): error CS0234: The type or namespace name 'Data' does not exist in the namespace 'Accounts' (are you missing an assembly reference?) [/app/Accounts.NT.csproj]
Controllers/AccountsController.cs(38,57): error CS0246: The type or namespace name 'AccountCreate' could not be found (are you missing a using directive or an assembly reference?) [/app/Accounts.NT.csproj]
Controllers/AccountsController.cs(19,26): error CS0246: The type or namespace name 'IAccountRepository' could not be found (are you missing a using directive or an assembly reference?) [/app/Accounts.NT.csproj]
Controllers/AccountsController.cs(21,35): error CS0246: The type or namespace name 'IAccountRepository' could not be found (are you missing a using directive or an assembly reference?) [/app/Accounts.NT.csproj]
The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1
The reason is you are copying from the root of the directory, where your file is inside
Src -> MyAPI -> MyAPI.csproj
So update your Dockerfile