Skip to content

Commit 621e630

Browse files
fix: NuGet auth config layering to fix 401 on private feed in Docker (#1062)
## Problem PR #1060 merged with the `--configfile` approach for Docker NuGet auth. This approach: - Discards the repo's `nuget.config` entirely (including `packageSourceMapping`) - Caused 401 Unauthorized on the Azure DevOps private feed The fixup commit from the original PR branch was never applied to main. ## Fix Switch to **NuGet config layering** (NuGet 5.7+): - CI generates a **credentials-only** config (no `<packageSources>`) - Dockerfile copies it to `~/.nuget/config/credentials.config` - NuGet merges it with the repo's `nuget.config` automatically - `nuget.config` remains the single source of truth for feeds + `packageSourceMapping` ### Changes - **`Dockerfile`**: `cp /run/secrets/nugetconfig ~/.nuget/config/credentials.config` instead of `--configfile`; add `required=false` on secret mount - **`Build-Test-And-Deploy.yml`**: credentials-only generated config (no `<packageSources>` section) ## Testing - PR build: uses `ACCESS_TO_NUGET_FEED=false` (no auth needed, verifies image builds) - Main build: full auth path with layered config --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 26ebbed commit 621e630

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

.github/workflows/Build-Test-And-Deploy.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ jobs:
7171
cat > /tmp/nuget-auth.config << EOF
7272
<?xml version="1.0" encoding="utf-8"?>
7373
<configuration>
74-
<packageSources>
75-
<clear />
76-
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
77-
<add key="EssentialCSharp" value="https://pkgs.dev.azure.com/intelliTect/_packaging/EssentialCSharp/nuget/v3/index.json" />
78-
</packageSources>
7974
<packageSourceCredentials>
8075
<EssentialCSharp>
8176
<add key="Username" value="docker" />

EssentialCSharp.Web/Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ ENV ACCESS_TO_NUGET_FEED=$ACCESS_TO_NUGET_FEED
1818
WORKDIR /src
1919
COPY . .
2020
COPY --from=frontend-build /frontend/EssentialCSharp.Web/wwwroot/dist ./EssentialCSharp.Web/wwwroot/dist
21-
RUN --mount=type=secret,id=nugetconfig \
21+
RUN --mount=type=secret,id=nugetconfig,required=false \
2222
if [ "$ACCESS_TO_NUGET_FEED" = "true" ] && [ -f /run/secrets/nugetconfig ]; then \
23-
dotnet restore "EssentialCSharp.Web.slnx" --configfile /run/secrets/nugetconfig -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED; \
24-
else \
25-
dotnet restore "EssentialCSharp.Web.slnx" -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED; \
23+
mkdir -p ~/.nuget/config && \
24+
cp /run/secrets/nugetconfig ~/.nuget/config/credentials.config; \
2625
fi && \
26+
dotnet restore "EssentialCSharp.Web.slnx" -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED && \
2727
dotnet build "EssentialCSharp.Web.slnx" -c Release --no-restore -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED -p:ReleaseDateAttribute=True -p:SkipFrontendBuild=true && \
28-
dotnet publish "EssentialCSharp.Web.slnx" -c Release -p:PublishDir=/app/publish -p:UseAppHost=false -p:SkipFrontendBuild=true --no-build
28+
dotnet publish "EssentialCSharp.Web.slnx" -c Release -p:PublishDir=/app/publish -p:UseAppHost=false -p:SkipFrontendBuild=true --no-build && \
29+
rm -f ~/.nuget/config/credentials.config
2930

3031
FROM base AS final
3132
WORKDIR /app

0 commit comments

Comments
 (0)