1

I have asp.net core solution, that contains 3 projects.

I want to deploy it to the docker container.

Here is how the solution looks like

enter image description here

Here is my Dockerfile

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

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

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

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

But when I run docker build I got this in console

Skipping project "/TooSeeWeb.Core/TooSeeWeb.Core.csproj" because it was not found.

Skipping project "/TooSeeWeb.Infrastructure/TooSeeWeb.Infrastructure.csproj" because it was not found.

MSBUILD : error MSB1009: Project file does not exist. Switch: TooSeeWeb.csproj

Error: ResponseItem.ErrorDetail[code=1,message=The command '/bin/sh -c dotnet build "TooSeeWeb.csproj" -c Release -o /app' returned a non-zero code: 1] Failed to deploy ' Dockerfile: TooSeeWeb/Dockerfile': The command '/bin/sh -c dotnet build "TooSeeWeb.csproj" -c Release -o /app' returned a non-zero code: 1

Where can be a problem?

UPDATE

Structure of folders of my solution

TooSeeWeb
 |- aspnet-core(folder)
    |-TooSeeWeb (folder)
      |- TooSeeWeb.sln
      |- TooSeeWeb
         |-Dockerfile
         |- TooSeeWeb.csproj
      |- TooSeeWeb.Core(folder)
         |- TooSeeWeb.Core.csproj
      |- TooSeeWeb.Infrastructure(folder)
         |- TooSeeWeb.Infrastructure.csproj

UPDATE2

I move dockerfile in the same folder with sln (it's one folder up)

Now my docker file looks like this

    ROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.sln ./
COPY TooSeeWeb/*.csproj ./TooSeeWeb/
COPY TooSeeWeb.Core/*.csproj ./TooSeeWeb.Core/
COPY TooSeeWeb.Infrastructure/.*csproj ./TooSeeWeb.Infrastructure/
RUN dotnet restore

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

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
WORKDIR /app/TooSeeWeb
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "tooseeweb.dll"]

But I got error

Step 4/14 : COPY *.sln ./ COPY failed: no source files were specified

1 Answer 1

2

The COPY command doesn't reproduce the same folder structure in the target folder, so your .csproj files are all in the same folder and the references are broken. Try adding

COPY TooSeeWeb.Core/*.csproj ./TooSeeWebCore/
COPY TooSeeWeb.Infrastructure/*.csproj ./TooSeeWeb.Infrastructure/

Update:
An example folder structure for a solution, with projects in subfolders

src
 |-my.sln
 |-Dockerfile
 |-Web (folder)
   |-web.csproj
 |-Core (folder)
   |-core.csproj
 |-Infrastructure (folder)
   |-infrastructure.csproj

The Dockerfile would be

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

# Copy csproj and restore as distinct layers
COPY *.sln ./
COPY Web/*.csproj ./Web/
COPY Core/*.csproj ./Core/
COPY Infrastructure/.*csproj ./Infrastructure/
RUN dotnet restore

# Copy everything else and build
COPY . ./
WORKDIR /app/Web
RUN dotnet build

Update 2
If there is no solution file then I think you need to dotnet restore each project individually

COPY Web/*.csproj ./Web/
COPY Core/*.csproj ./Core/
COPY Infrastructure/.*csproj ./Infrastructure/
RUN dotnet restore ./Web/Web.csproj
RUN dotnet restore ./Core/Core.csproj
RUN dotnet restore ./Infrastructure/Infrastructure.csproj
etc
Sign up to request clarification or add additional context in comments.

5 Comments

Step 4/12 : COPY TooSeeWeb.Core/*.csproj ./TooSeeWeb.Core/ Error: ResponseItem.ErrorDetail[code=<null>,message=COPY failed: no source files were specified] Failed to deploy '<unknown> Dockerfile: TooSeeWeb/Dockerfile': COPY failed: no source files were specified Go this now
So the Dockerfile is in the TooSeeWeb folder so you still have a problem with relative references. I have updated my answer to show one possible solution or you can keep your Dockerfile where it is and adjust the paths.
It not helps, or I do smth not right. I updated the question with a tree of solution
Look at my comment and updated answer. Move your Dockerfile up one folder and look at the structure of the Dockerfile I gave. Copy each project separately into a subfolder in the target. Be sure to add WORKDIR /app/TooSeeWeb before dotnet build.
I tried, docker cannot find .sln I updated question

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.