C
C#•3y ago
Robin Lindner

NuGet behind a proxy

Hey I am in the process of releasing a .NET project as a Docker container. How can I configure Nuget to use the proxy from the HTTP_PROXY & HTTPS_PROXY environment variables? Currently it fails on restore as it can't resolve the feed. Current Dockerfile:
FROM mcr.microsoft.com/dotnet/runtime:6.0-alpine AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
ARG HTTP_PROXY
ARG HTTPS_PROXY
ARG AZURE_DEVOPS_ACCESS_TOKEN
ENV HTTP_PROXY ${HTTP_PROXY}
ENV HTTPS_PROXY ${HTTPS_PROXY}
ENV AZURE_DEVOPS_ACCESS_TOKEN ${AZURE_DEVOPS_ACCESS_TOKEN}
WORKDIR /src
RUN dotnet nuget add source --name "my_feed" --username unused --store-password-in-clear-text --password ${AZURE_DEVOPS_ACCESS_TOKEN} "http://my_feed.tld/nuget/v3/index.json"
COPY ["tools/InboxCleanup/InboxCleanup.csproj", "tools/InboxCleanup/"]
COPY ["tools/lib/KMS.Tools.Common/KMS.Tools.Lib.Common.csproj", "tools/lib/KMS.Tools.Common/"]
RUN dotnet restore "tools/InboxCleanup/InboxCleanup.csproj"
COPY . .
WORKDIR "/src/tools/InboxCleanup"
RUN dotnet build "InboxCleanup.csproj" -c Release -o /app/build

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "InboxCleanup.dll"]
FROM mcr.microsoft.com/dotnet/runtime:6.0-alpine AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
ARG HTTP_PROXY
ARG HTTPS_PROXY
ARG AZURE_DEVOPS_ACCESS_TOKEN
ENV HTTP_PROXY ${HTTP_PROXY}
ENV HTTPS_PROXY ${HTTPS_PROXY}
ENV AZURE_DEVOPS_ACCESS_TOKEN ${AZURE_DEVOPS_ACCESS_TOKEN}
WORKDIR /src
RUN dotnet nuget add source --name "my_feed" --username unused --store-password-in-clear-text --password ${AZURE_DEVOPS_ACCESS_TOKEN} "http://my_feed.tld/nuget/v3/index.json"
COPY ["tools/InboxCleanup/InboxCleanup.csproj", "tools/InboxCleanup/"]
COPY ["tools/lib/KMS.Tools.Common/KMS.Tools.Lib.Common.csproj", "tools/lib/KMS.Tools.Common/"]
RUN dotnet restore "tools/InboxCleanup/InboxCleanup.csproj"
COPY . .
WORKDIR "/src/tools/InboxCleanup"
RUN dotnet build "InboxCleanup.csproj" -c Release -o /app/build

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "InboxCleanup.dll"]
5 Replies
Robin Lindner
Robin LindnerOP•3y ago
It is dotnet nuget and not the NuGet.exe, which is downloadable at nuget.org. Second is iirc only available on windows
SUPER MEGA T REX
SUPER MEGA T REX•3y ago
Ah, fair, it does appear you can generate a configuration (dotnet new nugetconfig) that you could then provide the values in.
SUPER MEGA T REX
SUPER MEGA T REX•3y ago
Although it would appear that you should be able to get away with just the environment variable set correctly (as per https://github.com/NuGet/Home/issues/6978)
GitHub
Issues · NuGet/Home
Repo for NuGet Client issues. Contribute to NuGet/Home development by creating an account on GitHub.
Robin Lindner
Robin LindnerOP•3y ago
as you see the env does not work 😄
Want results from more Discord servers?
Add your server