'Docker COPY [.dll]

I'm having an issue while creating a .NET Core application image on Docker. Basically in the image you can see this is a DLL file which I added as a reference in my project. While normal IIS built projects build and run smoothly, when I try to create an image it gives the following error. As far as I understand docker cannot find the DLL. I'm using a Linux Docker server.

Moreover, If I run Docker from "Desktop Docker" it runs smoothly but if I create image using "Docker Terminal" the below error occurs.

Build FAILED.
/usr/share/dotnet/sdk/2.1.803/Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "xxxxxx.Data.Core". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [/src/abcproject.Voucher.MySql/abcproject.Voucher.MySql.csproj]
Repository/SqlRepository.cs(1,7): error CS0246: The type or namespace name 'xxxxxx' could not be found (are you missing a using directive or an assembly reference?) [/src/abcproject.Voucher.MySql/abcproject.Voucher.MySql.csproj]
UnitOfWork/UnitOfWork.cs(1,7): error CS0246: The type or namespace name 'xxxxxx' could not be found (are you missing a using directive or an assembly reference?) [/src/abcproject.Voucher.MySql/abcproject.Voucher.MySql.csproj]
UnitOfWork/UnitOfWork.cs(2,7): error CS0246: The type or namespace name 'xxxxxx' could not be found (are you missing a using directive or an assembly reference?) [/src/abcproject.Voucher.MySql/abcproject.Voucher.MySql.csproj]
UnitOfWork/UnitOfWork.cs(13,31): error CS0246: The type or namespace name 'IUnitOfWork' could not be found (are you missing a using directive or an assembly reference?) [/src/abcproject.Voucher.MySql/abcproject.Voucher.MySql.csproj]
UnitOfWork/UnitOfWork.cs(30,16): error CS0246: The type or namespace name 'IRepository<>' could not be found (are you missing a using directive or an assembly reference?) [/src/abcproject.Voucher.MySql/abcproject.Voucher.MySql.csproj]
Repository/SqlRepository.cs(16,43): error CS0246: The type or namespace name 'RepositoryBase' could not be found (are you missing a using directive or an assembly reference?) [/src/abcproject.Voucher.MySql/abcproject.Voucher.MySql.csproj]
Repository/SqlRepository.cs(16,59): error CS0246: The type or namespace name 'IRepository<>' could not be found (are you missing a using directive or an assembly reference?) [/src/abcproject.Voucher.MySql/abcproject.Voucher.MySql.csproj]
UnitOfWork/UnitOfWork.cs(18,22): error CS0246: The type or namespace name 'RepositoryBase' could not be found (are you missing a using directive or an assembly reference?) [/src/abcproject.Voucher.MySql/abcproject.Voucher.MySql.csproj]
    1 Warning(s)
    8 Error(s)

Time Elapsed 00:00:15.67
The command '/bin/sh -c dotnet build "abcproject.Voucher.API.csproj" -c Release -o /app/build' returned a non-zero code: 1

Below is the Dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-stretch-slim AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build
WORKDIR /src
COPY ["abcproject.Voucher.API/abcproject.Voucher.API.csproj","abcproject.Voucher.API/"]
COPY ["abcproject.Voucher.Service/abcproject.Voucher.Service.csproj","abcproject.Voucher.Service/"]
COPY ["abcproject.Common/abcproject.Common.csproj", "abcproject.Common/"]
COPY ["abcproject.Voucher.MySql/abcproject.Voucher.MySql.csproj","abcproject.Voucher.MySql/"]
COPY ["abcproject.Voucher.Domain/abcproject.Voucher.Domain.csproj", "abcproject.Voucher.Domain/"]
RUN dotnet restore "abcproject.Voucher.API/abcproject.Voucher.API.csproj"
COPY . .
WORKDIR "/src/abcproject.Voucher.API"
RUN dotnet build "abcproject.Voucher.API.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "abcproject.Voucher.API.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "abcproject.Voucher.API.dll"]

This is the command I run to create an image:

docker build -t myimage -f "abcproject.Voucher.API/Dockerfile" .


Solution 1:[1]

Move your referenced .dll to the project main directory where you have your .csproj file. Docker will pick from there. Also, use COPY . .\

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 techies