C# dotnetcore api的Docker生成错误:跳过项目/MyDotnetCoreLib/MyDotnetCoreLib.csproj“;因为没有找到

C# dotnetcore api的Docker生成错误:跳过项目/MyDotnetCoreLib/MyDotnetCoreLib.csproj“;因为没有找到,c#,docker,.net-core,dotnet-core-pack,C#,Docker,.net Core,Dotnet Core Pack,我的问题背景。我正在尝试为dotnet core api生成docker映像,该api中有一个附加到api中引用的解决方案的库。当我运行docker build命令时,我收到下面的警告,然后生成错误,因为它无法引用库 正在跳过项目“/MyDotnetCoreLib/MyDotnetCoreLib.csproj”,因为找不到该项目 我的Dockerfile FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build-env WORKDIR /app C

我的问题背景。我正在尝试为dotnet core api生成docker映像,该api中有一个附加到api中引用的解决方案的库。当我运行docker build命令时,我收到下面的警告,然后生成错误,因为它无法引用库

正在跳过项目“/MyDotnetCoreLib/MyDotnetCoreLib.csproj”,因为找不到该项目

我的Dockerfile

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

COPY *.csproj ./
RUN dotnet restore

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

FROM mcr.microsoft.com/dotnet/core/aspnet:2.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "MyAPI.dll"]
我的文件结构如下:

--编辑

错误:

Sending build context to Docker daemon  1.426MB
Step 1/10 : FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build-env
 ---> bf77a711b92c
Step 2/10 : WORKDIR /app
 ---> Using cache
 ---> ae6b78cbf588
Step 3/10 : COPY src/Accounts.NT/Accounts.NT.csproj ./
COPY failed: stat /var/lib/docker/tmp/docker-builder190366239/src/Accounts.NT/Accounts.NT.csproj: no such file or directory
PS C:\Git\Personal\Accounts.NT\src\Accounts.NT> docker build -t vumanimdabe/accounts-nt:v1.0 .
Sending build context to Docker daemon  1.426MB
Step 1/10 : FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build-env
 ---> bf77a711b92c
Step 2/10 : WORKDIR /app
 ---> Using cache
 ---> ae6b78cbf588
Step 3/10 : COPY Accounts.NT.csproj ./
 ---> Using cache
 ---> b360913be4a4
Step 4/10 : RUN dotnet restore
 ---> Using cache
 ---> e9bf7172e851
Step 5/10 : COPY . ./
 ---> d4f088d6d737
Step 6/10 : RUN dotnet publish -c Release -o out
 ---> Running in fb8fad58131c
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Skipping project "/Accounts.Data/Accounts.Data.csproj" because it was not found.
  Skipping project "/Accounts.Data/Accounts.Data.csproj" because it was not found.
  Restore completed in 879.4 ms for /app/Accounts.NT.csproj.
/usr/share/dotnet/sdk/2.1.802/Microsoft.Common.CurrentVersion.targets(1875,5): warning : The referenced project '../Accounts.Data/Accounts.Data.csproj' does not exist. [/app/Accounts.NT.csproj]
Controllers/AccountsController.cs(7,16): error CS0234: The type or namespace name 'Data' does not exist in the namespace 'Accounts' (are you missing an assembly reference?) [/app/Accounts.NT.csproj]
Startup.cs(6,16): error CS0234: The type or namespace name 'Data' does not exist in the namespace 'Accounts' (are you missing an assembly reference?) [/app/Accounts.NT.csproj]
Startup.cs(7,16): error CS0234: The type or namespace name 'Data' does not exist in the namespace 'Accounts' (are you missing an assembly reference?) [/app/Accounts.NT.csproj]
Controllers/AccountsController.cs(38,57): error CS0246: The type or namespace name 'AccountCreate' could not be found (are you missing a using directive or an assembly reference?) [/app/Accounts.NT.csproj]
Controllers/AccountsController.cs(19,26): error CS0246: The type or namespace name 'IAccountRepository' could not be found (are you missing a using directive or an assembly reference?) [/app/Accounts.NT.csproj]
Controllers/AccountsController.cs(21,35): error CS0246: The type or namespace name 'IAccountRepository' could not be found (are you missing a using directive or an assembly reference?) [/app/Accounts.NT.csproj]
The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1

原因是您正在从目录的根目录进行复制,您的文件位于
Src->MyAPI->MyAPI.csproj

因此,请更新您的Dockerfile

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

COPY src/MyAPI/*.csproj ./
RUN dotnet restore

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

FROM mcr.microsoft.com/dotnet/core/aspnet:2.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "MyAPI.dll"]

我试过了。获取此语句的另一个错误:复制src/MyAPI/*.csproj./。复制失败:在it
src
src
中未指定源文件?仔细检查主机文件ITS
src
。检查主机文件是什么意思?我的意思是仔细检查文件名uder src/MyAPI以及dockerfile在哪里?有相同的问题。上面写着“因为在我的许多csproj文件中找不到”。其他错误是“找不到类型或命名空间名称”,因为它无法编译第一个项目。