gpt4 book ai didi

c# - 如何解决多个依赖 Web 应用程序时的依赖问题?

转载 作者:行者123 更新时间:2023-12-02 08:22:36 27 4
gpt4 key购买 nike

如何解决恢复依赖项 docker build 时未找到的问题?我得到了这个问题。我的文件结构如下所示。

请关注我的 Dockerfile:

[Solution] 'xxxxx' (3 Projects)  |   +-- [xxxxx.Web]  |    |  |    +--- xxxxx.Web.csproj (This project holds the Docker file)  |  +-- [xxxxx.xxxxserver]  |    |  |    +--- xxxxx.xxxxserver.csproj  |  +-- [xxxxx.xxxxApi.Client]       |       +--- xxxxx.xxxxApi.Client.csproj 1. xxxxx.Web.csproj -> API 2. xxxxx.xxxxserver/xxxxx.xxxxserver.csproj -> IdentityServer 3. xxxxx.xxxxApi.Client/xxxxx.xxxxApi.Client.csproj -> xxxxApi.Client

Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["xxxxx.Web.csproj", "./"]

COPY ["common.props", "./"]

RUN dotnet restore "xxxxx.Web.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "xxxxx.Web.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "xxxxx.Web.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "xxxxx.Web.dll"]

common.props:

<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>1.0.0</Version>
<NoWarn>$(NoWarn);CS1591;CS0436</NoWarn>
<AbpProjectType>app</AbpProjectType>
</PropertyGroup>
</Project>

最佳答案

在我看来,您复制文件的路径错误。并且您还需要复制 * .sln 文件。首先检查路径。

根据问题的描述,在我看来,将 Dockerfile 做成这样会更正确:

首先,将 Dockerfile 与 sln 文件齐平。

试试这个

COPY *.sln .
COPY xxxxx.Web/*.csproj ./xxxxx.Web/
COPY xxxxx.xxxserver/*.csproj ./xxxxx.xxxserver/
COPY xxxxx.xxxxApi.Client/*.csproj ./xxxxx.xxxxApi.Client/

RUN dotnet restore

COPY . .

WORKDIR /app/xxxxx.Web
RUN dotnet publish -c release -o /app --no-restore

更新:如果您没有 *.sln 文件,只需将 WORKDIR 更改为您的启动项目,如下所示:

COPY xxxxx.Web/*.csproj ./xxxxx.Web/
COPY xxxxx.xxxserver/*.csproj ./xxxxx.xxxserver/
COPY xxxxx.xxxxApi.Client/*.csproj ./xxxxx.xxxxApi.Client/

WORKDIR /app/xxxxx.Web

RUN dotnet restore

关于c# - 如何解决多个依赖 Web 应用程序时的依赖问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67213406/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com