Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .devcontainer/.env.template
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
114 changes: 114 additions & 0 deletions .devcontainer/README.md
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
```
16 changes: 14 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@
"image": "mcr.microsoft.com/devcontainers/dotnet",
"features": {
"ghcr.io/devcontainers/features/dotnet:2": {
"version": "latest"
"version": "9.0"
}
},
"postCreateCommand": "dotnet --list-sdks"
"containerEnv": {
"ACCESS_TO_NUGET_FEED": "true"
},
"postCreateCommand": ".devcontainer/setup-nuget-auth.sh",
"customizations": {
"vscode": {
"extensions": [
"ms-dotnettools.csharp",
"ms-dotnettools.csdevkit"
]
}
},
"remoteUser": "vscode"
}
52 changes: 52 additions & 0 deletions .devcontainer/setup-nuget-auth.sh
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
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!"
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml

EssentialCSharp.Web/Markdown/

EssentialCSharp.Web/Guidelines/
EssentialCSharp.Web/Markdown/

EssentialCSharp.Web/Guidelines/

# DevContainer environment files with sensitive data
.devcontainer/.env