From 98d3a81ed4a59bc5a8f370732f3b5fead2646fd0 Mon Sep 17 00:00:00 2001 From: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com> Date: Thu, 16 Apr 2026 11:42:59 +0100 Subject: [PATCH] Remove launchSettings, use .env for port configuration - Delete all launchSettings.json files (port 8088 now comes from ASPNETCORE_URLS in .env) - Add DotNetEnv to Hosted-Invocations-EchoAgent so it loads .env like the responses samples - Create .env.example for EchoAgent with ASPNETCORE_URLS and ASPNETCORE_ENVIRONMENT - Add AGENT_NAME to ChatClientAgent and FoundryAgent .env.example (required by those samples) - Add AZURE_BEARER_TOKEN=DefaultAzureCredential to all .env.example files - Update DevTemporaryTokenCredential in all 6 samples to treat the sentinel value as unavailable, allowing ChainedTokenCredential to fall through to DefaultAzureCredential - Update EchoAgent README with Configuration section --- .../Hosted-Invocations-EchoAgent/.env.example | 2 ++ .../Hosted-Invocations-EchoAgent.csproj | 1 + .../Hosted-Invocations-EchoAgent/Program.cs | 4 ++++ .../Properties/launchSettings.json | 11 ----------- .../Hosted-Invocations-EchoAgent/README.md | 10 ++++++++++ .../responses/Hosted-ChatClientAgent/.env.example | 3 ++- .../responses/Hosted-ChatClientAgent/Program.cs | 2 +- .../Properties/launchSettings.json | 11 ----------- .../responses/Hosted-FoundryAgent/.env.example | 3 ++- .../responses/Hosted-FoundryAgent/Program.cs | 2 +- .../Properties/launchSettings.json | 11 ----------- .../responses/Hosted-LocalTools/.env.example | 1 + .../responses/Hosted-LocalTools/Program.cs | 2 +- .../Hosted-LocalTools/Properties/launchSettings.json | 11 ----------- .../responses/Hosted-McpTools/.env.example | 1 + .../responses/Hosted-McpTools/Program.cs | 2 +- .../Hosted-McpTools/Properties/launchSettings.json | 11 ----------- .../responses/Hosted-TextRag/.env.example | 2 +- .../responses/Hosted-TextRag/Program.cs | 2 +- .../Hosted-TextRag/Properties/launchSettings.json | 11 ----------- .../responses/Hosted-Workflows/.env.example | 1 + .../responses/Hosted-Workflows/Program.cs | 2 +- .../Hosted-Workflows/Properties/launchSettings.json | 11 ----------- 23 files changed, 31 insertions(+), 86 deletions(-) create mode 100644 dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/.env.example delete mode 100644 dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/Properties/launchSettings.json delete mode 100644 dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/Properties/launchSettings.json delete mode 100644 dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/Properties/launchSettings.json delete mode 100644 dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/Properties/launchSettings.json delete mode 100644 dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/Properties/launchSettings.json delete mode 100644 dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/Properties/launchSettings.json delete mode 100644 dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflows/Properties/launchSettings.json diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/.env.example b/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/.env.example new file mode 100644 index 0000000000..46a6ae748c --- /dev/null +++ b/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/.env.example @@ -0,0 +1,2 @@ +ASPNETCORE_URLS=http://+:8088 +ASPNETCORE_ENVIRONMENT=Development diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/Hosted-Invocations-EchoAgent.csproj b/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/Hosted-Invocations-EchoAgent.csproj index b84faccf9e..d925172007 100644 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/Hosted-Invocations-EchoAgent.csproj +++ b/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/Hosted-Invocations-EchoAgent.csproj @@ -12,6 +12,7 @@ + diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/Program.cs b/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/Program.cs index 1650253dfc..d5944560ae 100644 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/Program.cs +++ b/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/Program.cs @@ -1,9 +1,13 @@ // Copyright (c) Microsoft. All rights reserved. using Azure.AI.AgentServer.Invocations; +using DotNetEnv; using HostedInvocationsEchoAgent; using Microsoft.Agents.AI; +// Load .env file if present (for local development) +Env.TraversePath().Load(); + var builder = WebApplication.CreateBuilder(args); // Register the echo agent as a singleton (no LLM needed). diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/Properties/launchSettings.json b/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/Properties/launchSettings.json deleted file mode 100644 index 7722815b12..0000000000 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/Properties/launchSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "profiles": { - "Hosted-Invocations-EchoAgent": { - "commandName": "Project", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "http://localhost:8088" - } - } -} diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/README.md b/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/README.md index 91bb9aac53..5fcfddab22 100644 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/README.md +++ b/dotnet/samples/04-hosting/FoundryHostedAgents/invocations/Hosted-Invocations-EchoAgent/README.md @@ -6,6 +6,16 @@ A minimal echo agent hosted as a Foundry Hosted Agent using the **Invocations pr - [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0) +## Configuration + +Copy the template: + +```bash +cp .env.example .env +``` + +> **Note:** `.env` is gitignored. The `.env.example` template is checked in as a reference. + ## Running directly (contributors) This project uses `ProjectReference` to build against the local Agent Framework source. diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/.env.example b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/.env.example index cbf693b3a9..984e8625cf 100644 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/.env.example +++ b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/.env.example @@ -2,4 +2,5 @@ AZURE_AI_PROJECT_ENDPOINT= ASPNETCORE_URLS=http://+:8088 ASPNETCORE_ENVIRONMENT=Development AZURE_AI_MODEL_DEPLOYMENT_NAME=gpt-4o -AZURE_BEARER_TOKEN= +AGENT_NAME=hosted-chat-client-agent +AZURE_BEARER_TOKEN=DefaultAzureCredential diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/Program.cs b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/Program.cs index 5e26322079..ee86bbae1b 100644 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/Program.cs +++ b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/Program.cs @@ -88,7 +88,7 @@ internal sealed class DevTemporaryTokenCredential : TokenCredential private AccessToken GetAccessToken() { - if (string.IsNullOrEmpty(this._token)) + if (string.IsNullOrEmpty(this._token) || this._token == "DefaultAzureCredential") { throw new CredentialUnavailableException($"{EnvironmentVariable} environment variable is not set."); } diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/Properties/launchSettings.json b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/Properties/launchSettings.json deleted file mode 100644 index cc21f3dd2e..0000000000 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-ChatClientAgent/Properties/launchSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "profiles": { - "Hosted-ChatClientAgent": { - "commandName": "Project", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "http://localhost:8088" - } - } -} \ No newline at end of file diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/.env.example b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/.env.example index 1fefe43ebd..77f0476f8d 100644 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/.env.example +++ b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/.env.example @@ -1,4 +1,5 @@ AZURE_AI_PROJECT_ENDPOINT= ASPNETCORE_URLS=http://+:8088 ASPNETCORE_ENVIRONMENT=Development -AZURE_BEARER_TOKEN= +AGENT_NAME=hosted-foundry-agent +AZURE_BEARER_TOKEN=DefaultAzureCredential diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/Program.cs b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/Program.cs index 11069c6403..b593b16671 100644 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/Program.cs +++ b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/Program.cs @@ -81,7 +81,7 @@ internal sealed class DevTemporaryTokenCredential : TokenCredential private AccessToken GetAccessToken() { - if (string.IsNullOrEmpty(this._token)) + if (string.IsNullOrEmpty(this._token) || this._token == "DefaultAzureCredential") { throw new CredentialUnavailableException($"{EnvironmentVariable} environment variable is not set."); } diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/Properties/launchSettings.json b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/Properties/launchSettings.json deleted file mode 100644 index b4c4e005d3..0000000000 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-FoundryAgent/Properties/launchSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "profiles": { - "HostedFoundryAgent": { - "commandName": "Project", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "http://localhost:8088" - } - } -} \ No newline at end of file diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/.env.example b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/.env.example index 6d7831229d..b8fe9e8e7a 100644 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/.env.example +++ b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/.env.example @@ -2,3 +2,4 @@ AZURE_AI_PROJECT_ENDPOINT= ASPNETCORE_URLS=http://+:8088 ASPNETCORE_ENVIRONMENT=Development AZURE_AI_MODEL_DEPLOYMENT_NAME=gpt-4o +AZURE_BEARER_TOKEN=DefaultAzureCredential diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/Program.cs b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/Program.cs index 20a9cf079a..f0e3566fe1 100644 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/Program.cs +++ b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/Program.cs @@ -154,7 +154,7 @@ internal sealed class DevTemporaryTokenCredential : TokenCredential private AccessToken GetAccessToken() { - if (string.IsNullOrEmpty(this._token)) + if (string.IsNullOrEmpty(this._token) || this._token == "DefaultAzureCredential") { throw new CredentialUnavailableException($"{EnvironmentVariable} environment variable is not set."); } diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/Properties/launchSettings.json b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/Properties/launchSettings.json deleted file mode 100644 index ae1bb80b7d..0000000000 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-LocalTools/Properties/launchSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "profiles": { - "HostedLocalTools": { - "commandName": "Project", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "http://localhost:8088" - } - } -} diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/.env.example b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/.env.example index 6d7831229d..b8fe9e8e7a 100644 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/.env.example +++ b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/.env.example @@ -2,3 +2,4 @@ AZURE_AI_PROJECT_ENDPOINT= ASPNETCORE_URLS=http://+:8088 ASPNETCORE_ENVIRONMENT=Development AZURE_AI_MODEL_DEPLOYMENT_NAME=gpt-4o +AZURE_BEARER_TOKEN=DefaultAzureCredential diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/Program.cs b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/Program.cs index 0e97e5f84f..a027047a1d 100644 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/Program.cs +++ b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/Program.cs @@ -120,7 +120,7 @@ internal sealed class DevTemporaryTokenCredential : TokenCredential private AccessToken GetAccessToken() { - if (string.IsNullOrEmpty(this._token)) + if (string.IsNullOrEmpty(this._token) || this._token == "DefaultAzureCredential") { throw new CredentialUnavailableException($"{EnvironmentVariable} environment variable is not set."); } diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/Properties/launchSettings.json b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/Properties/launchSettings.json deleted file mode 100644 index 3042eb4d44..0000000000 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/Properties/launchSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "profiles": { - "HostedMcpTools": { - "commandName": "Project", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "http://localhost:8088" - } - } -} diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/.env.example b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/.env.example index cbf693b3a9..b8fe9e8e7a 100644 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/.env.example +++ b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/.env.example @@ -2,4 +2,4 @@ AZURE_AI_PROJECT_ENDPOINT= ASPNETCORE_URLS=http://+:8088 ASPNETCORE_ENVIRONMENT=Development AZURE_AI_MODEL_DEPLOYMENT_NAME=gpt-4o -AZURE_BEARER_TOKEN= +AZURE_BEARER_TOKEN=DefaultAzureCredential diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/Program.cs b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/Program.cs index 45d027f740..33edb58901 100644 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/Program.cs +++ b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/Program.cs @@ -120,7 +120,7 @@ internal sealed class DevTemporaryTokenCredential : TokenCredential private static AccessToken GetAccessToken() { var token = Environment.GetEnvironmentVariable(EnvironmentVariable); - if (string.IsNullOrEmpty(token)) + if (string.IsNullOrEmpty(token) || token == "DefaultAzureCredential") { throw new CredentialUnavailableException($"{EnvironmentVariable} environment variable is not set."); } diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/Properties/launchSettings.json b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/Properties/launchSettings.json deleted file mode 100644 index 932d4e67fc..0000000000 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-TextRag/Properties/launchSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "profiles": { - "HostedTextRag": { - "commandName": "Project", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "http://localhost:8088" - } - } -} diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflows/.env.example b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflows/.env.example index 6d7831229d..b8fe9e8e7a 100644 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflows/.env.example +++ b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflows/.env.example @@ -2,3 +2,4 @@ AZURE_AI_PROJECT_ENDPOINT= ASPNETCORE_URLS=http://+:8088 ASPNETCORE_ENVIRONMENT=Development AZURE_AI_MODEL_DEPLOYMENT_NAME=gpt-4o +AZURE_BEARER_TOKEN=DefaultAzureCredential diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflows/Program.cs b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflows/Program.cs index 279daf5f24..558aef11d4 100644 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflows/Program.cs +++ b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflows/Program.cs @@ -87,7 +87,7 @@ internal sealed class DevTemporaryTokenCredential : TokenCredential private AccessToken GetAccessToken() { - if (string.IsNullOrEmpty(this._token)) + if (string.IsNullOrEmpty(this._token) || this._token == "DefaultAzureCredential") { throw new CredentialUnavailableException($"{EnvironmentVariable} environment variable is not set."); } diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflows/Properties/launchSettings.json b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflows/Properties/launchSettings.json deleted file mode 100644 index 0e2908985a..0000000000 --- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-Workflows/Properties/launchSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "profiles": { - "HostedWorkflows": { - "commandName": "Project", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "http://localhost:8088" - } - } -}