user1765862
user1765862

Reputation: 14205

Docker file The current working > directory does not contain a project or solution file

On issuing command: docker build -t honda-api:build .

Step 7/10 : RUN dotnet restore ---> Running in beedd0465f48 MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.

Folder structure look like this

        Domain/
            Honda.Domain/
                Honda.Domain.csproj
        API/
            Honda.API/
                Honda.API.csproj
        Dockerfile

Docker file content

    FROM mcr.microsoft.com/dotnet/core/sdk:3.1 
    WORKDIR /home/app 
    COPY . . 
    COPY ./Domain/Honda.Domain/Honda.Domain.csproj Domain/
    COPY ./API/Honda.API/Honda.API.csproj API/
    
    RUN dotnet restore 
    RUN dotnet publish ./Honda.API.csproj -o /publish/ 
    WORKDIR /publish ENV ASPNETCORE_URLS=https://+:5001;http://+:5000 
    ENTRYPOINT ["dotnet", "Honda.API.dll"]

Upvotes: 3

Views: 9530

Answers (1)

eduherminio
eduherminio

Reputation: 1694

If you don't copy a .sln file at root level that groups all your projects, you need to run dotnet restore over each one of the project directories or .csproj files, i.e.:

RUN dotnet restore ./API
RUN dotnet restore ./API/Honda.API.csproj

However, I wouldn't follow your approach of copying everything following the same project structure and then the .csproj files with a custom one, better keep everything as it is ad follow this approach.

Something like this (also, probably using the runtime image for running the app, instead of the sdk one, and using Release configuration):

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /app 

# copy csproj and restore as distinct layers
COPY *.sln .
COPY ./Domain/Honda.Domain/*.csproj ./Domain/Honda.Domain/
COPY ./API/Honda.API/*.csproj ./API/Honda.API/
RUN dotnet restore

# copy everything else and build app
COPY . ./
WORKDIR /app/API/Honda.API
RUN dotnet publish -c Release -o publish 

FROM mcr.microsoft.com/dotnet/aspnet:3.1
WORKDIR /app
COPY --from=build /app/API/Honda.API/publish  ./
ENV ASPNETCORE_URLS=https://+:5001;http://+:5000 
ENTRYPOINT ["dotnet", "Honda.API.dll"]

I have not tested that, but hopefully you can tweak it and fix any minor issues it has.

Upvotes: 6

Related Questions