33
44echo " 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
137echo " 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"
3714fi
3815
3916# Display .NET version
4017echo " Checking .NET SDK version..."
4118dotnet --version
4219
43- # Try to restore packages
20+ # Try to restore packages with interactive authentication if credential provider is available
4421echo " 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
4744else
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
5052fi
5153
5254echo " π Devcontainer setup complete!"
0 commit comments