我有一个简单的 ASP.NET Core 2.0 应用程序,解决方案中有 2 个项目。一个项目是一个类库 (WorldLibrary.dll),它被 Web 应用程序 (WeatherWeb.dll) 引用。
我已尝试按照此处的步骤操作:
https://docs.docker.com/engine/examples/dotnetcore/
这是我的 Dockerfile:
FROM microsoft/aspnetcore-build:2.0 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 microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "WeatherWeb.dll"]
但是,引用的 .dll 存在问题。我从“docker build”命令得到以下输出:
C:\Users\olavt\source\repos\Weather\WeatherWeb>docker build -t weather .
Sending build context to Docker daemon 6.398MB
Step 1/10 : FROM microsoft/aspnetcore-build:2.0 AS build-env
---> df4c9af52c86
Step 2/10 : WORKDIR /app
---> Using cache
---> ae9d1b099da7
Step 3/10 : COPY *.csproj ./
---> Using cache
---> 2d9f3fba6470
Step 4/10 : RUN dotnet restore
---> Using cache
---> 19af5fb355a3
Step 5/10 : COPY . ./
---> 1704520a3ced
Step 6/10 : RUN dotnet publish -c Release -o out
---> Running in 7bcdf847e4dc
/usr/share/dotnet/sdk/2.0.2/NuGet.targets(792,5): warning MSB3202: The project file "/WorldLibrary/WorldLibrary.csproj" was not found. [/app/WeatherWeb.csproj]
Microsoft (R) Build Engine version 15.4.8.50001 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
/usr/share/dotnet/sdk/2.0.2/Microsoft.Common.CurrentVersion.targets(1768,5): warning : The referenced project '../WorldLibrary/WorldLibrary.csproj' does not exist. [/app/WeatherWeb.csproj]
Controllers/Api/WeatherController.cs(6,7): error CS0246: The type or namespace name 'WorldLibrary' could not be found (are you missing a using directive or an assembly reference?) [/app/WeatherWeb.csproj]
Controllers/WeatherController.cs(6,7): error CS0246: The type or namespace name 'WorldLibrary' could not be found (are you missing a using directive or an assembly reference?) [/app/WeatherWeb.csproj]
Controllers/Api/WeatherController.cs(14,39): error CS0246: The type or namespace name 'Weather' could not be found (are you missing a using directive or an assembly reference?) [/app/WeatherWeb.csproj]
The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1
C:\Users\olavt\source\repos\Weather\WeatherWeb>
我应该如何正确地将引用的 .dll 正确复制过来?
最佳答案
如果是相关项目,您必须对您的解决方案文件运行 dotnet restore
和 dotnet publish
并将您的 docker 文件放在解决方案级别,以便您可以访问它的所有项目。
基本上,您需要在 docker 文件中进行的唯一更改是:
COPY *.sln ./
COPY ./your_proj1_folder/*.csproj ./your_proj1_folder/
COPY ./your_proj2_folder/*.csproj ./your_proj2_folder/
RUN dotnet restore
https://stackoverflow.com/questions/46775215/
相关文章:
docker - 失败 : port is already allocated
docker - 如何使用 docker-compose yml 文件进行生产?
docker - Jenkins 2.0 : Running SBT in a docker con
php - 在双 nginx 反向代理中正确处理 request_uri?
java - 如何在Docker中初始化数据库后启动flyway
python - 如何将包含所有依赖项的 python 包安装到 Docker 镜像中?
docker - 是否可以使用 Winscp 连接到正在运行的 docker 容器?
macos - 在 docker 中运行 Webpack-dev-server 比在本地机器上运行要