c# - dotnetcore api : Skipping project "/MyDotnetCoreLib/MyDotnetCoreLib.csproj" because it was not found 的 Docker 构建错误

标签 c# docker .net-core dotnet-core-pack

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

Skipping project "/MyDotnetCoreLib/MyDotnetCoreLib.csproj" because it was not found.

我的 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"]

我的文件结构如下:

screenshot of the file structure

--编辑 screenshot of the file structure

错误:

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"]

关于c# - dotnetcore api : Skipping project "/MyDotnetCoreLib/MyDotnetCoreLib.csproj" because it was not found 的 Docker 构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58337878/

相关文章:

c# - Web API 'Request' 为空

docker - 如何使用 apparmor 在 docker 容器中启用挂载文件系统

docker - 重新启动ubuntu后无法访问本地主机中的站点

.net - 找不到框架 'Microsoft.NETCore.App' ,版本 '5' ,而找到 Microsoft.NETCore.App 5.0.0

c# - 是否有与 StreamReader 的 Peek 方法等效的异步方法?

c# - 使用 Microsoft.Exchange.WebServices 的 SSIS 脚本任务

javascript - 在 javascript 中调用 C# 函数,它在页面加载之前执行。为什么?

c# - 用户控制自定义事件并设置获取属性

docker - Rancher 外部子域

.net - 使用 VS2017 在 iisexpress 上部署 ASP.NET 核心 2.0 Web 应用程序导致 HTTP 错误 502.3 - 错误网关