Skip to content

Commit be160fb

Browse files
Implement interactive authentication for devcontainer NuGet access
Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
1 parent a97396c commit be160fb

3 files changed

Lines changed: 34 additions & 42 deletions

File tree

β€Ž.devcontainer/.env.templateβ€Ž

Lines changed: 0 additions & 7 deletions
This file was deleted.

β€Ž.devcontainer/devcontainer.jsonβ€Ž

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
"version": "9.0"
66
}
77
},
8-
"containerEnv": {
9-
"ACCESS_TO_NUGET_FEED": "true"
10-
},
118
"postCreateCommand": ".devcontainer/setup-nuget-auth.sh",
129
"customizations": {
1310
"vscode": {

β€Ž.devcontainer/setup-nuget-auth.shβ€Ž

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,52 @@ set -e
33

44
echo "Setting up NuGet authentication for Azure DevOps..."
55

6-
# Load environment variables from .env file if it exists
7-
if [ -f ".devcontainer/.env" ]; then
8-
echo "Loading environment variables from .devcontainer/.env..."
9-
set -o allexport; source .devcontainer/.env; set +o allexport
10-
fi
11-
126
# Install Azure Artifacts Credential Provider
137
echo "Installing Azure Artifacts Credential Provider..."
14-
if ! sh -c "$(curl -fsSL https://aka.ms/install-artifacts-credprovider.sh)" 2>/dev/null; then
8+
if sh -c "$(curl -fsSL https://aka.ms/install-artifacts-credprovider.sh)" 2>/dev/null; then
9+
echo "βœ… Azure Artifacts Credential Provider installed successfully"
10+
else
1511
echo "⚠️ Could not download Azure Artifacts Credential Provider installer."
16-
echo "This may be due to network restrictions. The provider will be installed later if needed."
17-
fi
18-
19-
# Check if AZURE_DEVOPS_PAT is set
20-
if [ -z "$AZURE_DEVOPS_PAT" ]; then
21-
echo ""
22-
echo "⚠️ AZURE_DEVOPS_PAT environment variable is not set."
23-
echo "To enable private NuGet feed access, you need to:"
24-
echo "1. Create a Personal Access Token (PAT) in Azure DevOps with 'Packaging (read)' permissions"
25-
echo "2. Add it to your devcontainer environment by creating a .devcontainer/.env file:"
26-
echo " AZURE_DEVOPS_PAT=your_pat_token_here"
27-
echo "3. Or set it as a codespace secret named 'AZURE_DEVOPS_PAT'"
28-
echo ""
29-
echo "For now, setting AccessToNugetFeed=false to allow restore without private packages..."
12+
echo "This may be due to network restrictions. Falling back to public packages only."
3013
export ACCESS_TO_NUGET_FEED=false
31-
else
32-
echo "AZURE_DEVOPS_PAT found, setting up authentication..."
33-
# Set up the credential provider environment
34-
export VSS_NUGET_EXTERNAL_FEED_ENDPOINTS="{\"endpointCredentials\": [{\"endpoint\":\"https://pkgs.dev.azure.com/intelliTect/_packaging/EssentialCSharp/nuget/v3/index.json\", \"password\":\"$AZURE_DEVOPS_PAT\"}]}"
35-
export ACCESS_TO_NUGET_FEED=true
36-
echo "βœ… NuGet authentication configured for Azure DevOps private feed"
3714
fi
3815

3916
# Display .NET version
4017
echo "Checking .NET SDK version..."
4118
dotnet --version
4219

43-
# Try to restore packages
20+
# Try to restore packages with interactive authentication if credential provider is available
4421
echo "Attempting to restore NuGet packages..."
45-
if dotnet restore -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED; then
46-
echo "βœ… Package restoration successful!"
22+
if command -v dotnet-credential-provider-installer >/dev/null 2>&1 || [ -n "$(find ~/.nuget -name "*CredentialProvider*" 2>/dev/null | head -1)" ]; then
23+
echo ""
24+
echo "πŸ” The credential provider is available for Azure DevOps authentication."
25+
echo "If prompted for credentials during package restoration, you can:"
26+
echo " 1. Use your Azure DevOps account credentials, or"
27+
echo " 2. Create a Personal Access Token (PAT) with 'Packaging (read)' permissions"
28+
echo " from: https://dev.azure.com/intelliTect/_usersSettings/tokens"
29+
echo ""
30+
31+
# First try to restore with interactive authentication for private packages
32+
if dotnet restore --interactive -p:AccessToNugetFeed=true; then
33+
echo "βœ… Package restoration successful with private feed access!"
34+
else
35+
echo "⚠️ Private package restoration failed or was cancelled."
36+
echo "Falling back to public packages only..."
37+
if dotnet restore -p:AccessToNugetFeed=false; then
38+
echo "βœ… Package restoration successful with public packages only!"
39+
else
40+
echo "❌ Package restoration failed completely."
41+
exit 1
42+
fi
43+
fi
4744
else
48-
echo "❌ Package restoration failed. Check your Azure DevOps PAT if you need private packages."
49-
exit 1
45+
echo "Credential provider not available, using public packages only..."
46+
if dotnet restore -p:AccessToNugetFeed=false; then
47+
echo "βœ… Package restoration successful with public packages only!"
48+
else
49+
echo "❌ Package restoration failed."
50+
exit 1
51+
fi
5052
fi
5153

5254
echo "πŸŽ‰ Devcontainer setup complete!"

0 commit comments

Comments
Β (0)