Home > Back-end >  .csproj not found when building with dockerfile
.csproj not found when building with dockerfile

Time:01-16

I've created a blank solution with rider. This solution has 1 console app with a simple Hello World!

enter image description here

I've generated an automatic dockerfile by right clicking on the csproj --> Add --> Docker support.

Here is the DockerFile generated

FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base WORKDIR /app

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

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

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

When I run a docker build . command

I get .csproj not found exception.

enter image description here

I have 0 idea why. Everything is as simple as possible. Yet my csproj is not found.

Any ideas on how to fix this?

Edit: Hans Kilian Response

After using docker build .. I get this message error: failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount4071044659/Dockerfile: no such file or directory

CodePudding user response:

It looks like your Dockerfile expects that the build context is the 'DockerTest' folder rather than the 'RootFolder' folder.

The context is what you specify as the last argument on the docker build command.

So instead of

docker build .

try

docker build -f Dockerfile ..

Another way to solve it is to move the Dockerfile up to the 'DockerTest' directory and then run docker build . from there.

  • Related