0

I am very much new on docker technology, I am getting the build error while creating the .Net Core 3.1 on Azure DevOps CI pipeline on Docker image tasks:

Step 7/17 : COPY ["API2/API2.csproj", "API2/"] COPY failed: CreateFile \?\C:\ProgramData\docker\tmp\docker-builder021493529\API2\API2.csproj: The system cannot find the path specified.

My default docker file is

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base 
WORKDIR /app 
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build
WORKDIR /src
COPY ["API1/API1.csproj", "API1/"]
RUN dotnet restore "API1/API1.csproj"
COPY . .
WORKDIR "/src/API1"
RUN dotnet build "API1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "API1.csproj" -c Release -o /app/publish
FROM base AS final 
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "API1.dll"] 

Please do let me know from where I am doing mistake.

Here are the docker tasks:

enter image description here

Here are the folder and files structure on azure DevOps as well:

file structure

6
  • Can you share your Docker build task in Azure DevOps? Commented Dec 30, 2019 at 15:04
  • @ShaykiAbramczyk Please find the images pasted on question section Commented Dec 31, 2019 at 6:37
  • Why do you use task version 0? Commented Dec 31, 2019 at 6:59
  • there is no specific reason i can use 2.* as well, but as per point now i used 2.* version but still facing the same issue Commented Dec 31, 2019 at 9:19
  • In version 2 which value do you have in the Context field?. Commented Dec 31, 2019 at 9:20

1 Answer 1

1

COPY ["API1/API1.csproj", "API1/"]

Based on the error message, this should the line that caused the error message.

Step1:

Please ensure you did not configure the .dockerignore file to exclude this file: API1/API1.csproj, which must exists in the directory where you run your build from.

Step2:

After above confirmed, now we can consider the error is caused about the server could not find the csproj file correctly by following the context and the path you provided.


According to the your original definition: API1/API1.csproj, I guess the actual path of API1.csproj in your repository should be src/API1/API1.csproj, right?

If yes, here has 2 method you can try:

1). Change the COPY definition as:

    COPY ["API1.csproj", "API1/"]

Updated:

When you apply this method, you may succeed to COPY, but failed with Program does not contain a static 'Main' method suitable for an entry point *****.

Here it means that the COPY . . does not copy the files correctly.

At this time, please also change the COPY . . to COPY . API1/. This will add folder to dest path.

2). Another way is you could specify API1 to Build context in task:

Below is what I am using, and I do not need make any changes into my dockerfile:

you can input $(Build.Repository.LocalPath) by replacing hard code the context:

enter image description here

Updated:

In Docker 2.*, you can also leave Build context to **:

enter image description here

You can refer to my previous answer on such question: #1.


Based on my opinions, I am not recommend the first method I mentioned above, because it let your dockerfile different with the one which you can run successfully in Visual studio.

Sign up to request clarification or add additional context in comments.

6 Comments

thanks @Merlin for posting the detail reply to my query: well I go for 1st step and i changed COPY ["API2.csproj", "API2/"] , now build proceed to next level and now i am facing another error Program does not contain a static 'Main' method suitable for an entry point [C:\src\API2\API2.csproj] 0 Warning(s) 1 Error(s)"
@SaadAwan, Okay, this is what I do not want you faced. Please change the line 9 to COPY . API1/ to add folder to dest path. As I suggest in my answer, I strongly suggest you use the second method which do not need make changes into dockerfile. In addition, here I have the same puzzle with shayki, why not use docker 2.* task? Any trouble with that?
now i am using docker tasks 2.* and add the brand new docker file which vs 2019 created, and add build context $(Build.Repository.LocalPath), but still same result API2\API2.csproj: The system cannot find the path specified
@SaadAwan. For CI, it is by default running the docker in the directory where the dockerfile lives which is at the project level, but VS runs it at the Repos/Solution level. How's your file structure? That's why here you can input $(Build.Repository.LocalPath). Not sure why this is not suitable for you (on my side it is work fine), please make the context to ** and build again. I update my answer to make it more clear. You can check it.
@SaadAwan, filebin.net/ofx8y31wmpn6tv5n/dockerfile.txt?t=w8g9rpqh This is the dockerfile which I modified based on your dockerfile. Note the order of WORKDIR /src/TestWebApp and COPY . ., this way could let you avoid the error of Program does not contain a static 'Main' method. And for docker 2.* task, you do not need change any default value, just like this: imgur.com/a/k7jvnfo This is the solution 1 I mentioned in my answer. And different with my answer, here I change the order of COPY and WORKDIR, then you don't need change the COPY . .
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.