Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
230 changes: 230 additions & 0 deletions .github/agents/claude.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
# Claude Agent Instructions for Azure Functions .NET Template

## Repository Context
This repository contains an Azure Functions HTTP trigger quickstart template written in C# (.NET isolated worker model) and deployed to Azure Functions Flex Consumption using Azure Developer CLI (azd). The template emphasizes security with managed identity and optional VNet integration.

## Critical Guidelines

### 1. .NET Version Management

**Current Configuration: .NET 10**

Before making any .NET version changes, you MUST:
1. Fetch and verify current support from: https://learn.microsoft.com/en-us/azure/azure-functions/supported-languages
2. Confirm the version is GA (Generally Available), not preview

**Files requiring updates for .NET version changes:**
```
http/http.csproj - <TargetFramework>net10.0</TargetFramework>
infra/main.bicep - runtimeVersion: '10.0' (around line 113)
README.md - Prerequisites: .NET SDK link
.vscode/tasks.json - Path: bin/Debug/net10.0
.vscode/settings.json - deploySubpath: bin/Release/net10.0/publish
azure.yaml - name: starter-dotnet10-flex-func
```

### 2. NuGet Package Dependencies

**Current Package Versions (as of .NET 10 upgrade):**
```xml
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.51.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.3.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.7" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.50.0" />
```

**Package Update Protocol:**
- Only use stable/GA versions (no preview, beta, or rc)
- Verify compatibility between packages before updating
- Check release notes for breaking changes
- **Important**: Microsoft.ApplicationInsights.WorkerService 3.x has breaking OpenTelemetry changes - stay on 2.22.0 for compatibility
- Always test locally after updates

**Where to check versions:**
- NuGet.org package pages
- GitHub releases for azure-functions-dotnet-worker
- Azure Functions documentation

### 3. Infrastructure Configuration (Bicep)

**Key Settings in infra/main.bicep:**
```bicep
runtimeName: 'dotnet-isolated' // Always isolated worker model
runtimeVersion: '10.0' // Must match .NET version
```

**Infrastructure Architecture:**
- Hosting: Flex Consumption (SKU: FC1)
- Runtime: Functions v4
- Model: Isolated worker process
- Authentication: Managed Identity (UserAssigned)
- Storage: Keyless access via managed identity
- Networking: Optional VNet (parameter: vnetEnabled)

### 4. Security Requirements

**Non-negotiable security practices:**
- Use managed identity for all Azure resource access
- Storage accounts must use `allowSharedKeyAccess: false`
- Minimum TLS 1.2 for all connections
- VNet integration available via VNET_ENABLED parameter
- No storage account keys in configuration

**Authentication Configuration:**
```json
{
"AzureWebJobsStorage__credential": "managedidentity",
"AzureWebJobsStorage__clientId": "<identity-client-id>"
}
```

### 5. Local Development Setup

**Required local.settings.json (http/ directory):**
```json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
}
}
```

**Prerequisites:**
- .NET 10 SDK
- Azure Functions Core Tools (v4)
- Azure Developer CLI (azd)
- Azurite for local storage emulation (optional but recommended)

### 6. Testing Workflow

**For any code changes:**
```bash
# 1. Build the project
cd http
dotnet build

# 2. Run locally
func start

# 3. Test endpoints
curl http://localhost:7071/api/httpget
curl -X POST http://localhost:7071/api/httppost \
-H "Content-Type: application/json" \
-d @testdata.json

# 4. Deploy to Azure
cd ..
azd up
```

### 7. Code Structure

**Function Definitions:**
- `http/httpGetFunction.cs` - HTTP GET endpoint
- `http/httpPostBodyFunction.cs` - HTTP POST with JSON body
- `http/Program.cs` - Host configuration with Application Insights

**Key Patterns:**
- Use `[Function("name")]` attribute for endpoint naming
- Use `[HttpTrigger(AuthorizationLevel.Function, "method")]` for triggers
- Use `[FromBody]` for request body deserialization
- Inject `ILogger<T>` for structured logging

### 8. Common Maintenance Tasks

**Upgrading .NET Version:**
1. Verify Azure Functions support (check Microsoft Learn docs)
2. Update all 6 files listed in section 1
3. Update NuGet packages to compatible versions
4. Test build: `dotnet build http/http.csproj`
5. Test run: `cd http && func start`
6. Test deployment: `azd up` (in test environment)
7. Verify endpoints work post-deployment

**Updating Dependencies:**
1. Check latest stable versions on NuGet.org
2. Review release notes for breaking changes
3. Update related packages together (e.g., all Worker packages)
4. Update Application Insights packages together
5. Test locally before committing

**Modifying Infrastructure:**
1. Edit Bicep files in `infra/` directory
2. Maintain security best practices (managed identity, no keys)
3. Test with `azd up` in development environment
4. Verify no regression in VNet support

### 9. Template Propagation Context

This repository serves as a **source template** for the Azure Functions AZD template family. Changes made here may need to be propagated to related templates:
- Other language variants (Python, JavaScript, TypeScript, Java)
- Other hosting models (Consumption, Premium, Dedicated)

**Propagation workflow:** See `.github/prompts/.propagation/` directory

### 10. Documentation Standards

**When updating code:**
- Update README.md if prerequisites or setup steps change
- Update inline code comments if business logic changes
- Keep CHANGELOG.md updated (if applicable)
- Ensure sample code in README.md stays synchronized

**README.md sections to maintain:**
- Prerequisites (SDK versions)
- Local setup instructions
- Deployment instructions
- Source code examples

### 11. Important Constraints

**Do NOT:**
- Use preview/beta NuGet packages without explicit requirement
- Remove security features (managed identity, TLS requirements)
- Change to in-process model (must stay isolated worker)
- Add storage account keys to configuration
- Disable VNet support (keep optional)

**Always DO:**
- Ground version decisions in official Azure Functions documentation
- Test locally before pushing changes
- Update all related configuration files together
- Maintain backward compatibility where possible
- Document breaking changes clearly

### 12. Verification Checklist

Before completing any task:
- [ ] All files updated consistently
- [ ] Build succeeds locally (`dotnet build`)
- [ ] Functions run locally (`func start`)
- [ ] Tests pass (if applicable)
- [ ] Documentation updated
- [ ] Security practices maintained
- [ ] Azure Functions support verified from official docs

## Support Resources

- **Official Docs**: https://learn.microsoft.com/en-us/azure/azure-functions/
- **Supported Languages**: https://learn.microsoft.com/en-us/azure/azure-functions/supported-languages
- **Isolated Worker Guide**: https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide
- **NuGet Packages**: https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker
- **GitHub Repo**: https://github.com/Azure/azure-functions-dotnet-worker

## Response Protocol

When asked to update .NET versions or packages:
1. Acknowledge the request
2. State that you will verify current support from official documentation
3. Fetch the support information
4. Propose changes based on verified information
5. List all files that need updates
6. Execute changes systematically
7. Test the changes
8. Report results

This ensures all guidance is grounded in current, authoritative information.
93 changes: 93 additions & 0 deletions .github/agents/copilot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# GitHub Copilot Agent Instructions for Azure Functions .NET Template

## Overview
This repository contains an Azure Functions HTTP trigger template written in C# using the isolated worker model and deployed using Azure Developer CLI (azd). The template is designed for Flex Consumption hosting with managed identity and optional VNet integration for secure deployments.

## Key Guidelines

### 1. .NET Version Management
- **Current Target Framework**: .NET 10 (`net10.0`)
- **Always verify supported .NET versions** by checking the official Azure Functions documentation at: https://learn.microsoft.com/en-us/azure/azure-functions/supported-languages
- When updating .NET versions, update ALL of the following files:
- `http/http.csproj` - TargetFramework property
- `infra/main.bicep` - runtimeVersion parameter (line ~113)
- `README.md` - Prerequisites section SDK link
- `.vscode/tasks.json` - cwd path references
- `.vscode/settings.json` - deploySubpath
- `azure.yaml` - name field

### 2. NuGet Package Management
Always use the latest **stable** (non-preview) versions of packages:

**Core Packages:**
- `Microsoft.Azure.Functions.Worker` - Core isolated worker functionality
- `Microsoft.Azure.Functions.Worker.Sdk` - Build-time SDK
- `Microsoft.Azure.Functions.Worker.Extensions.Http` - HTTP trigger support
- `Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore` - ASP.NET Core integration

**Monitoring Packages:**
- `Microsoft.ApplicationInsights.WorkerService` - Application Insights base (use 2.22.0, not 3.x due to breaking changes)
- `Microsoft.Azure.Functions.Worker.ApplicationInsights` - Functions-specific telemetry

**Version Checking:**
- Check NuGet.org for latest stable versions before updating
- Avoid preview/rc packages unless explicitly required
- **Important**: Use ApplicationInsights.WorkerService 2.22.0, not 3.x (3.0+ has breaking changes incompatible with current Functions Worker)
- Test locally after any package updates

### 3. Infrastructure as Code (Bicep)
- Runtime configuration is in `infra/main.bicep` and `infra/app/api.bicep`
- The template uses:
- `runtimeName: 'dotnet-isolated'` (always isolated worker model)
- `runtimeVersion: '10.0'` (matches .NET version)
- Azure Functions v4 runtime (`AzureFunctionsVersion: v4`)
- Flex Consumption SKU (`FC1`)

### 4. Security Best Practices
- Use managed identity for Azure resource authentication (already configured)
- Storage accounts use managed identity credentials (no keys)
- VNet integration is optional but recommended (controlled via `VNET_ENABLED` parameter)
- TLS 1.2 minimum for storage accounts

### 5. Local Development
- Requires `local.settings.json` with `FUNCTIONS_WORKER_RUNTIME: "dotnet-isolated"`
- Use Azurite for local storage emulation
- Azure Functions Core Tools required for `func start`

### 6. Testing Changes
When making changes:
1. Build locally: `dotnet build http/http.csproj`
2. Run functions: `cd http && func start`
3. Test endpoints: `httpget` and `httppost`
4. Verify deployment: `azd up`

### 7. Template Propagation
This is a source template - changes may need to be propagated to other Azure Functions templates in the family. See `.github/prompts/.propagation/` for automation workflows.

## Common Tasks

### Upgrade .NET Version
1. Check official support: https://learn.microsoft.com/en-us/azure/azure-functions/supported-languages
2. Update csproj TargetFramework
3. Update NuGet packages to compatible versions
4. Update infra/main.bicep runtimeVersion
5. Update README.md prerequisites
6. Update VS Code configuration files
7. Test build and deployment

### Update NuGet Packages
1. Check for latest stable versions on NuGet.org
2. Update all related packages together for compatibility
3. Test build locally
4. Verify Application Insights integration still works

### Modify Infrastructure
1. Changes to Bicep files should maintain security defaults
2. Test with `azd up` in a dev environment
3. Document any new parameters or configuration options

## Important Notes
- Always test changes locally before committing
- Maintain backwards compatibility where possible
- Document breaking changes clearly
- Keep README.md synchronized with code changes
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"azureFunctions.deploySubpath": "http/bin/Release/net8.0/publish",
"azureFunctions.deploySubpath": "http/bin/Release/net10.0/publish",
"azureFunctions.projectLanguage": "C#",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen",
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"type": "func",
"dependsOn": "build (functions)",
"options": {
"cwd": "${workspaceFolder}/http/bin/Debug/net8.0"
"cwd": "${workspaceFolder}/http/bin/Debug/net10.0"
},
"command": "host start",
"isBackground": true,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This codespace is already configured with the required tools to complete this tu

## Prerequisites

+ [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0)
+ [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0)
+ [Azure Functions Core Tools](https://learn.microsoft.com/azure/azure-functions/functions-run-local?pivots=programming-language-csharp#install-the-azure-functions-core-tools)
+ To use Visual Studio to run and debug locally:
+ [Visual Studio 2022](https://visualstudio.microsoft.com/vs/).
Expand Down
2 changes: 1 addition & 1 deletion azure.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json

name: starter-dotnet8-flex-func
name: starter-dotnet10-flex-func
metadata:
template: functions-quickstart-dotnet-azd@1.1.0
services:
Expand Down
12 changes: 6 additions & 6 deletions http/http.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.51.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.3.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.2" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.5" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.23.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.7" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.50.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
Expand Down
2 changes: 1 addition & 1 deletion infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module api './app/api.bicep' = {
applicationInsightsName: monitoring.outputs.name
appServicePlanId: appServicePlan.outputs.resourceId
runtimeName: 'dotnet-isolated'
runtimeVersion: '8.0'
runtimeVersion: '10.0'
storageAccountName: storage.outputs.name
enableBlob: storageEndpointConfig.enableBlob
enableQueue: storageEndpointConfig.enableQueue
Expand Down