【问题标题】:How to create local nuget packages for docker?如何为 docker 创建本地 nuget 包?
【发布时间】:2021-11-23 09:15:17
【问题描述】:

我想为 docker 创建本地 nuget 包 在 nuget.config 中,为 nuget 存储库添加“C:\Program Files (x86)\Microsoft SDKs\NuGetPackages”,在运行时,docker 在地址的第一个添加“src”并且找不到“src\C:\程序文件 (x86)\Microsoft SDKs\NuGetPackages"

如何在“localhost:8000”上创建本地nuget包?

我的 Dockerfile 是:

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

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src

COPY "solution-name.sln" "PadCMS.sln"

COPY "BuildingBlocks/Core/Core.Common/Core.Common.csproj" "BuildingBlocks/Core/Core.Common/Core.Common.csproj"
COPY "BuildingBlocks/Core/Core.WebApi/Core.WebApi.csproj" "BuildingBlocks/Core/Core.WebApi/Core.WebApi.csproj"
COPY "BuildingBlocks/Core/Core/Core.csproj" "BuildingBlocks/Core/Core/Core.csproj"
COPY "BuildingBlocks/Devspaces.Support/Devspaces.Support.csproj" "BuildingBlocks/Devspaces.Support/Devspaces.Support.csproj"
COPY "BuildingBlocks/EventBus/EventBus/EventBus.csproj" "BuildingBlocks/EventBus/EventBus/EventBus.csproj"
COPY "BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.csproj" "BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.csproj"
COPY "BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj" "BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj"
COPY "BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEF.csproj" "BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEF.csproj"
COPY "BuildingBlocks/WebHostCustomization/WebHost.Customization/WebHost.Customization.csproj" "BuildingBlocks/WebHostCustomization/WebHost.Customization/WebHos

COPY "NuGet.config" "NuGet.config"

RUN dotnet restore "PadCMS.sln"


COPY . .
WORKDIR /src/Services/Accounting/Accounting.API
RUN dotnet publish --no-restore -c Release -o /app

FROM build AS publish

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

【问题讨论】:

  • 您的 docker 容器无法访问您的正常文件系统,因此它无法访问 C:\..(即使路径正确)。您要做的是将您COPY 的某个目录中的 nuget 包包含到容器中。如果您将容器内该目录的路径添加到您的NuGet.Config 中,那么dotnet 应该能够使用该包源。

标签: docker .net-core docker-compose nuget


【解决方案1】:
  1. 你不能在c:\...中使用你下载的包,因为它是文件系统。
  2. 要创建本地 NuGet 包存储库,您可以使用 BaGet。 BaGet 还支持与 docker 一起运行,并有 documentation 关于它。 安装后,您必须将应用程序使用的所有包上传到本地 nuget 存储库。然后需要在应用程序文件夹中放置nuget.config 文件才能仅使用这样的本地 nuget 存储库
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="local" value="your local address" protocolVersion="3" />
  </packageSources>
</configuration>

但我不推荐这个,推荐使用this

【讨论】:

  • 我在 "c:\program file\..." 中使用过包,但 docker 正在从 "src\c:\..." 中读取,所以我也找不到它们在docker上安装了BaGet,但是docker run nuget/findbyid,BaGet没有这个地址
  • 可以发一份样品吗?
  • @rezamalekmohamadi 你不能使用 c:\ 。对于 BaGet,我完成了答案
  • 是的,但是当我运行 docker-compose 时,docker 在地址的第一个自动添加了“src”,然后找不到它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-07
相关资源
最近更新 更多