Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Devops Pipeline - file not found in build context

Getting an error in the Azure DevOps Pipeline:

Step 7/17 : COPY ["demo6/demo6.csproj", "demo6/"]
COPY failed: file not found in build context or excluded by .dockerignore: stat demo6/demo6.csproj: file does not exist

NOTES-run the pipeline in diagnostics mode and the .sln file exists

##[debug]cwd=/home/vsts/work/1/s
##[debug]  /home/vsts/work/1/s/demo6.sln (file)
##[debug]  /home/vsts/work/1/s/demo6/demo6.csproj (file)

I have a multi-project Asp.Net Core solution with the folder structure and projects as follows:

demo6
 |--demo6/demo6.csproj
 |--demo6.api/demo6.api.csproj

The app is demo6 which references demo6.api which is a class library.

This is in GitHub in a repository demo6. I modified the autogenerated Dockerfile to add the extra demo6/ to see if that works but no.

Appreciate any help.

Dockerfile below:

FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["demo6/demo6.csproj", "demo6/"]
RUN dotnet restore "demo6/demo6.csproj"
COPY . .
WORKDIR "/src/demo6"
RUN dotnet build "demo6.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "demo6.csproj" -c Release -o /app/publish

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

Also tried this:

FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["demo6/demo6/demo6.csproj", "ddemo6/"]
RUN dotnet restore "ddemo6/demo6.csproj"
COPY . .
WORKDIR "/src/ddemo6"
RUN dotnet build "demo6.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "demo6.csproj" -c Release -o /app/publish

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

Got this error:

Step 7/17 : COPY ["demo6/demo6/demo6.csproj", "ddemo6/"]
COPY failed: file not found in build context or excluded by .dockerignore: stat demo6/demo6/demo6.csproj: file does not exist
##[error]COPY failed: file not found in build context or excluded by .dockerignore: stat demo6/demo6/demo6.csproj: file does not exist

here's the repo structureenter image description here

like image 425
Kumar Avatar asked Oct 26 '22 12:10

Kumar


1 Answers

The reason of file not found error may be the relative path of the Dockerfile and the csproj are different. Try to set the Dockerfile in the root of the solution should solve your error.

Also you need to add a buildContext with the csproj folder.

buildContext: Path to the build context

Also, here is a case you can refer to.

One more possible cause of COPY failed: no source files were specified is .dockerignore file present in your workspace

Look for .dockerignore file because of docker’s CLI (command line interface) it sends context to the docker daemon to load the .dockerignore file.

If the .dockerignore file exist in the context than it might be possible there is exclude entry to ignore the build directory

# ignore or exclude build directory
*/build*
*/*/build*
like image 186
Sreeram Nair Avatar answered Nov 11 '22 18:11

Sreeram Nair