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
This commit is contained in:
Roger Barreto
2026-04-16 11:42:59 +01:00
parent d49d546bb4
commit 98d3a81ed4
23 changed files with 31 additions and 86 deletions
@@ -0,0 +1,2 @@
ASPNETCORE_URLS=http://+:8088
ASPNETCORE_ENVIRONMENT=Development
@@ -12,6 +12,7 @@
<ItemGroup>
<PackageReference Include="Azure.AI.AgentServer.Invocations" />
<PackageReference Include="DotNetEnv" />
</ItemGroup>
<!-- For contributors: uses ProjectReference to build against local source -->
@@ -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).
@@ -1,11 +0,0 @@
{
"profiles": {
"Hosted-Invocations-EchoAgent": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:8088"
}
}
}
@@ -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.
@@ -2,4 +2,5 @@ AZURE_AI_PROJECT_ENDPOINT=<your-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
@@ -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.");
}
@@ -1,11 +0,0 @@
{
"profiles": {
"Hosted-ChatClientAgent": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:8088"
}
}
}
@@ -1,4 +1,5 @@
AZURE_AI_PROJECT_ENDPOINT=<your-azure-ai-project-endpoint>
ASPNETCORE_URLS=http://+:8088
ASPNETCORE_ENVIRONMENT=Development
AZURE_BEARER_TOKEN=
AGENT_NAME=hosted-foundry-agent
AZURE_BEARER_TOKEN=DefaultAzureCredential
@@ -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.");
}
@@ -1,11 +0,0 @@
{
"profiles": {
"HostedFoundryAgent": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:8088"
}
}
}
@@ -2,3 +2,4 @@ AZURE_AI_PROJECT_ENDPOINT=<your-azure-ai-project-endpoint>
ASPNETCORE_URLS=http://+:8088
ASPNETCORE_ENVIRONMENT=Development
AZURE_AI_MODEL_DEPLOYMENT_NAME=gpt-4o
AZURE_BEARER_TOKEN=DefaultAzureCredential
@@ -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.");
}
@@ -1,11 +0,0 @@
{
"profiles": {
"HostedLocalTools": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:8088"
}
}
}
@@ -2,3 +2,4 @@ AZURE_AI_PROJECT_ENDPOINT=<your-azure-ai-project-endpoint>
ASPNETCORE_URLS=http://+:8088
ASPNETCORE_ENVIRONMENT=Development
AZURE_AI_MODEL_DEPLOYMENT_NAME=gpt-4o
AZURE_BEARER_TOKEN=DefaultAzureCredential
@@ -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.");
}
@@ -1,11 +0,0 @@
{
"profiles": {
"HostedMcpTools": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:8088"
}
}
}
@@ -2,4 +2,4 @@ AZURE_AI_PROJECT_ENDPOINT=<your-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
@@ -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.");
}
@@ -1,11 +0,0 @@
{
"profiles": {
"HostedTextRag": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:8088"
}
}
}
@@ -2,3 +2,4 @@ AZURE_AI_PROJECT_ENDPOINT=<your-azure-ai-project-endpoint>
ASPNETCORE_URLS=http://+:8088
ASPNETCORE_ENVIRONMENT=Development
AZURE_AI_MODEL_DEPLOYMENT_NAME=gpt-4o
AZURE_BEARER_TOKEN=DefaultAzureCredential
@@ -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.");
}
@@ -1,11 +0,0 @@
{
"profiles": {
"HostedWorkflows": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:8088"
}
}
}