Home > Net >  dotnet restore not finding folder while running dockerfile
dotnet restore not finding folder while running dockerfile

Time:05-23

This is a very simple API I've created with .NET 6 and ASP.NET Core that I'm trying to dockerize.

I'm always getting the same error while running docker build command. this is my docker file:

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore "MyAPI/MyAPI.csproj" //this is where the build stops


# Copy everything else and build
COPY .. ./
RUN dotnet publish -c Release -o out 


# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
EXPOSE 80
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "MyAPI.dll"]

this is the error I'm getting :

=> ERROR [build-env 4/6] RUN dotnet restore                                                                                                               0.7s 
------
 > [build-env 4/6] RUN dotnet restore:
#11 0.676 MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
------
executor failed running [/bin/sh -c dotnet restore]: exit code: 1

I guess the problem is a path problem and I've tried my ways to pass in the path to my folder yet it kept giving me the same error.

If I try to run the dotnet restore command individually in the terminal, it works which tells me that the path is correct.

What could be the problem?

CodePudding user response:

COPY *.csproj ./ doesn't find anything to copy, since your .csproj file is in the MyAPI/ directory.

Change the statement to

COPY MyAPI/MyAPI.csproj MyAPI/

Where you copy the rest of the files and publish the project should also be changed to

COPY . ./
RUN dotnet publish -c Release -o out MyAPI/MyAPI.csproj

CodePudding user response:

Please check if the csproj file really exists in your PC file system on the path yourSolutionRootFolder/MyAPI/MyAPI.csproj

You may have a typo in the path? Upper/lower case typo?

  • Related