dotnetcore api的Docker生成错误:跳过项目“ /MyDotnetCoreLib/MyDotnetCoreLib.csproj”,因为未找到

时间:2019-10-11 09:09:20

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

关于我的问题的背景。我正在尝试为dotnet核心api构建一个docker映像,该api的API引用了该解决方案附带的库,当我运行docker build命令时,我得到以下警告,然后由于无法引用该库而生成错误。 / p>

  

正在跳过项目“ /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"]

我的文件结构如下:

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

1 个答案:

答案 0 :(得分:0)

原因是您要从目录的根目录复制文件,该目录位于<androidx.viewpager.widget.ViewPager android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" />

因此更新您的Dockerfile

Src -> MyAPI -> MyAPI.csproj