-
Notifications
You must be signed in to change notification settings - Fork 8
Fix devcontainer to properly restore projects with private NuGet feed using interactive authentication #778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
BenjaminMichaelis
merged 5 commits into
main
from
copilot/fix-203be6e9-ae45-42ab-858c-004e79e534ba
Sep 20, 2025
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
be71b20
Initial plan
Copilot 5c04b11
Implement devcontainer authentication for private NuGet feed
Copilot 9fba55c
Update .devcontainer/setup-nuget-auth.sh
BenjaminMichaelis a97396c
Delete .devcontainer/README.md
BenjaminMichaelis be160fb
Implement interactive authentication for devcontainer NuGet access
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Template for devcontainer environment variables | ||
| # Copy this file to .env and fill in your values | ||
|
|
||
| # Azure DevOps Personal Access Token (PAT) with Packaging (read) permissions | ||
| # Get this from: https://dev.azure.com/intelliTect/_usersSettings/tokens | ||
| # Required permissions: Packaging (read) | ||
| AZURE_DEVOPS_PAT=your_pat_token_here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| # DevContainer Setup for EssentialCSharp.Web | ||
|
|
||
| This project includes a DevContainer configuration for development with Visual Studio Code and GitHub Codespaces. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - [Visual Studio Code](https://code.visualstudio.com/) with the [Remote-Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) | ||
| - [Docker Desktop](https://www.docker.com/products/docker-desktop) (for local development) | ||
|
|
||
| ## Private NuGet Feed Authentication | ||
|
|
||
| This project uses a private Azure DevOps NuGet feed for some packages. To access these packages, you need to set up authentication. | ||
|
|
||
| ### For GitHub Codespaces | ||
|
|
||
| 1. Create a Personal Access Token (PAT) in Azure DevOps: | ||
| - Go to https://dev.azure.com/intelliTect/_usersSettings/tokens | ||
| - Click "New Token" | ||
| - Name: "EssentialCSharp DevContainer" | ||
| - Scopes: Select "Packaging (read)" | ||
| - Click "Create" | ||
|
|
||
| 2. Add the token as a Codespace secret: | ||
| - Go to your GitHub repository settings | ||
| - Navigate to "Codespaces" → "Repository secrets" | ||
| - Click "New repository secret" | ||
| - Name: `AZURE_DEVOPS_PAT` | ||
| - Value: Your Azure DevOps PAT | ||
|
|
||
| ### For Local Development | ||
|
|
||
| 1. Create a Personal Access Token (PAT) in Azure DevOps (same as above) | ||
|
|
||
| 2. Create a `.env` file in the `.devcontainer` directory: | ||
| ```bash | ||
| cp .devcontainer/.env.template .devcontainer/.env | ||
| ``` | ||
|
|
||
| 3. Edit `.devcontainer/.env` and replace `your_pat_token_here` with your actual PAT: | ||
| ``` | ||
| AZURE_DEVOPS_PAT=your_actual_pat_token_here | ||
| ``` | ||
|
|
||
| ⚠️ **Important**: Never commit the `.env` file to source control as it contains sensitive information. | ||
|
|
||
| ## Opening the DevContainer | ||
|
|
||
| ### In VS Code (Local) | ||
| 1. Open the repository in VS Code | ||
| 2. When prompted, click "Reopen in Container" | ||
| 3. Or use Command Palette (Ctrl+Shift+P): "Remote-Containers: Reopen in Container" | ||
|
|
||
| ### In GitHub Codespaces | ||
| 1. Click the "Code" button on the GitHub repository | ||
| 2. Select "Codespaces" tab | ||
| 3. Click "Create codespace on main" | ||
|
|
||
| ## What Happens During Setup | ||
|
|
||
| The DevContainer will automatically: | ||
|
|
||
| 1. Install the .NET 9.0 SDK | ||
| 2. Install Azure Artifacts Credential Provider | ||
| 3. Configure NuGet authentication (if PAT is provided) | ||
| 4. Restore NuGet packages | ||
| 5. Set up VS Code extensions for C# development | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Package Restoration Fails | ||
|
|
||
| If package restoration fails: | ||
|
|
||
| 1. **Check your PAT**: Ensure it has "Packaging (read)" permissions | ||
| 2. **Verify the PAT**: Test it manually with: | ||
| ```bash | ||
| curl -u :YOUR_PAT https://dev.azure.com/intelliTect/_apis/packaging/feeds | ||
| ``` | ||
| 3. **Check environment**: Ensure `AZURE_DEVOPS_PAT` is set correctly | ||
|
|
||
| ### DevContainer Won't Start | ||
|
|
||
| 1. **Check Docker**: Ensure Docker Desktop is running | ||
| 2. **Check VS Code Extensions**: Ensure Remote-Containers extension is installed | ||
| 3. **Rebuild Container**: Use Command Palette: "Remote-Containers: Rebuild Container" | ||
|
|
||
| ### No Access to Private Packages | ||
|
|
||
| If you don't have access to the private Azure DevOps feed: | ||
|
|
||
| 1. The setup script will automatically set `AccessToNugetFeed=false` | ||
| 2. Private packages will be excluded from the build | ||
| 3. The project will still build and run with public packages only | ||
|
|
||
| ## Available Commands | ||
|
|
||
| Once the DevContainer is running, you can use these commands: | ||
|
|
||
| ```bash | ||
| # Restore packages | ||
| dotnet restore | ||
|
|
||
| # Build the solution | ||
| dotnet build | ||
|
|
||
| # Run tests | ||
| dotnet test | ||
|
|
||
| # Run the web application | ||
| dotnet run --project EssentialCSharp.Web | ||
|
|
||
| # Run the chat application | ||
| dotnet run --project EssentialCSharp.Chat | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| echo "Setting up NuGet authentication for Azure DevOps..." | ||
|
|
||
| # Load environment variables from .env file if it exists | ||
| if [ -f ".devcontainer/.env" ]; then | ||
| echo "Loading environment variables from .devcontainer/.env..." | ||
| export $(grep -v '^#' .devcontainer/.env | xargs) | ||
| fi | ||
|
|
||
| # Install Azure Artifacts Credential Provider | ||
| echo "Installing Azure Artifacts Credential Provider..." | ||
| if ! sh -c "$(curl -fsSL https://aka.ms/install-artifacts-credprovider.sh)" 2>/dev/null; then | ||
BenjaminMichaelis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| echo "⚠️ Could not download Azure Artifacts Credential Provider installer." | ||
| echo "This may be due to network restrictions. The provider will be installed later if needed." | ||
| fi | ||
|
|
||
| # Check if AZURE_DEVOPS_PAT is set | ||
| if [ -z "$AZURE_DEVOPS_PAT" ]; then | ||
| echo "" | ||
| echo "⚠️ AZURE_DEVOPS_PAT environment variable is not set." | ||
| echo "To enable private NuGet feed access, you need to:" | ||
| echo "1. Create a Personal Access Token (PAT) in Azure DevOps with 'Packaging (read)' permissions" | ||
| echo "2. Add it to your devcontainer environment by creating a .devcontainer/.env file:" | ||
| echo " AZURE_DEVOPS_PAT=your_pat_token_here" | ||
| echo "3. Or set it as a codespace secret named 'AZURE_DEVOPS_PAT'" | ||
| echo "" | ||
| echo "For now, setting AccessToNugetFeed=false to allow restore without private packages..." | ||
| export ACCESS_TO_NUGET_FEED=false | ||
| else | ||
| echo "AZURE_DEVOPS_PAT found, setting up authentication..." | ||
| # Set up the credential provider environment | ||
| export VSS_NUGET_EXTERNAL_FEED_ENDPOINTS="{\"endpointCredentials\": [{\"endpoint\":\"https://pkgs.dev.azure.com/intelliTect/_packaging/EssentialCSharp/nuget/v3/index.json\", \"password\":\"$AZURE_DEVOPS_PAT\"}]}" | ||
| export ACCESS_TO_NUGET_FEED=true | ||
| echo "✅ NuGet authentication configured for Azure DevOps private feed" | ||
| fi | ||
|
|
||
| # Display .NET version | ||
| echo "Checking .NET SDK version..." | ||
| dotnet --version | ||
|
|
||
| # Try to restore packages | ||
| echo "Attempting to restore NuGet packages..." | ||
| if dotnet restore -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED; then | ||
| echo "✅ Package restoration successful!" | ||
| else | ||
| echo "❌ Package restoration failed. Check your Azure DevOps PAT if you need private packages." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "🎉 Devcontainer setup complete!" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.