title: MSBUILD : error MSB1009: Project file does not exist when building docker file for an ASP.NET Core API application
body: <p>I am trying to build a docker image for an ASP.NET Core 3.1 application and I fail to restore the packages. My solution has multiple projects and after copying all the project files, I am trying to create a layer which contains restored dependencies only.</p>
  
  <h3>The docker file</h3>
  
  <pre><code>FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
  WORKDIR /app
  EXPOSE 80
  
  FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
  WORKDIR /src
  COPY ["ExampleApi/ExampleApi.csproj", "ExampleApi/ExampleApi/"]
  COPY ["Common.Web/Common.Web.csproj", "ExampleApi/Common.Web/"]
  COPY ["Example.Data/Example.Data.csproj", "ExampleApi/Example.Data/"]
  COPY ["Example.Services/Example.Services.csproj", "ExampleApi/Example.Services/"]
  
  RUN mkdir /tmp/build/
  COPY . /tmp/build
  RUN find /tmp/build -name *.csproj
  
  RUN dotnet restore "ExampleApi/ExampleApi.csproj" --verbosity detailed
  COPY . .
  WORKDIR "/src/ExampleApi/ExampleApi"
  RUN dotnet build "ExampleApi.csproj" -c Release -o /app --no-restore
  
  FROM build AS publish
  RUN dotnet publish "ExampleApi.csproj" -c Release -o /app
  
  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app .
  ENTRYPOINT ["dotnet", "ExampleApi.dll"]
  </code></pre>
  
  <h3>Docker build</h3>
  
  <p>I am running without cache to be able to output all the csproj files within the container for each run (otherwise it gets cached and the files are not longer displayed).</p>
  
  <pre><code>docker build --no-cache -f ExampleApi/Dockerfile .
  
  Sending build context to Docker daemon  116.4MB
  Step 1/22 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
   ---&gt; a843e0fbe833
  Step 2/22 : WORKDIR /app
   ---&gt; Running in e33e9c821c0b
  Removing intermediate container e33e9c821c0b
   ---&gt; eec973a226e0
  Step 3/22 : EXPOSE 80
   ---&gt; Running in 8e813a3a8b85
  Removing intermediate container 8e813a3a8b85
   ---&gt; c8d95a3a1de4
  Step 4/22 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
   ---&gt; cef7866e800b
  Step 5/22 : WORKDIR /src
   ---&gt; Running in f56bf9402ed1
  Removing intermediate container f56bf9402ed1
   ---&gt; 55694332db0e
  Step 6/22 : COPY ["ExampleApi/ExampleApi.csproj", "ExampleApi/ExampleApi/"]
   ---&gt; 4beb2e169ec7
  Step 7/22 : COPY ["Common.Web/Common.Web.csproj", "ExampleApi/Common.Web/"]
   ---&gt; ed7a9c81e8f7
  Step 8/22 : COPY ["Example.Data/Example.Data.csproj", "ExampleApi/Example.Data/"]
   ---&gt; aaca52c111b4
  Step 9/22 : COPY ["Example.Services/Example.Services.csproj", "ExampleApi/Example.Services/"]
   ---&gt; efb15c17a096
  Step 10/22 : RUN mkdir /tmp/build/
   ---&gt; Running in 7da9eae324ca
  Removing intermediate container 7da9eae324ca
   ---&gt; b06126b19a7f
  Step 11/22 : COPY . /tmp/build
   ---&gt; 04598eaab98c
  Step 12/22 : RUN find /tmp/build -name *.csproj
   ---&gt; Running in 2fd26dba963d
  /tmp/build/ExampleApi/ExampleApi.csproj
  /tmp/build/Example.Data/Example.Data.csproj
  /tmp/build/Common.Web/Common.Web.csproj
  /tmp/build/Example.Sql/Example.!Sql.csproj
  /tmp/build/Example.Services/Example.Services.csproj
  /tmp/build/Example.Services.Tests/Example.Services.Tests.csproj
  /tmp/build/Example.IdentityServer.Infrastructure/Example.IdentityServer.Infrastructure.csproj
  /tmp/build/Example.IdentityServer/Example.IdentityServer.csproj
  /tmp/build/Example.Data.Tests/Example.Data.Tests.csproj
  /tmp/build/ExampleIntegrationApi/ExampleIntegrationApi.csproj
  Removing intermediate container 2fd26dba963d
   ---&gt; 78eadf796305
  Step 13/22 : RUN dotnet restore "ExampleApi/ExampleApi.csproj" --verbosity detailed
   ---&gt; Running in 5dc9b5bbd04e
  MSBUILD : error MSB1009: Project file does not exist.
  Switch: ExampleApi/ExampleApi.csproj
  The command '/bin/sh -c dotnet restore "ExampleApi/ExampleApi.csproj" --verbosity detailed' returned a non-zero code: 1
  </code></pre>
  
  <p><code>find</code> indicates that <code>ExampleApi/ExampleApi.csproj</code> is there, yet the <code>dotnet restore</code> complains about not finding it.</p>