From 2e1eef07db5ea5d05c0e082f7f8cbbe99681fc51 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 May 2025 00:39:51 +0000 Subject: [PATCH 1/6] Initial plan for issue From 809957569662bfb47c4df46cb0e78786b1460da0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 May 2025 00:51:57 +0000 Subject: [PATCH 2/6] Update WebJobHelloWorld sample to .NET 8 Co-authored-by: zhenlan <10566826+zhenlan@users.noreply.github.com> --- .../WebJobs/WebJobHelloWorld/README.md | 42 +++++++++ .../WebJobHelloWorld/Functions.cs | 21 ++--- .../WebJobHelloWorld/Program.cs | 94 +++++++++---------- .../WebJobHelloWorld/WebJobHelloWorld.csproj | 16 ++-- 4 files changed, 106 insertions(+), 67 deletions(-) create mode 100644 examples/DotNetCore/WebJobs/WebJobHelloWorld/README.md diff --git a/examples/DotNetCore/WebJobs/WebJobHelloWorld/README.md b/examples/DotNetCore/WebJobs/WebJobHelloWorld/README.md new file mode 100644 index 00000000..9686256c --- /dev/null +++ b/examples/DotNetCore/WebJobs/WebJobHelloWorld/README.md @@ -0,0 +1,42 @@ +# WebJob Hello World Sample + +This sample demonstrates how to build a .NET 8 WebJobs application that uses Azure App Configuration to store and retrieve configurations. + +## Prerequisites + +- [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) +- Azure subscription with an App Configuration instance +- Azure Storage account + +## How it works + +This sample WebJob connects to Azure App Configuration to retrieve settings such as the Azure Storage connection string and queue name. It then listens to the specified queue for messages and logs them. + +## Getting Started + +1. Set the environment variable `ConnectionString` to your Azure App Configuration connection string: + + ```bash + # Windows + set ConnectionString= + + # Linux/macOS + export ConnectionString= + ``` + +2. Make sure you have the following configuration values set in your Azure App Configuration instance: + - `WebJob:AzureWebJobsStorage` - Your Azure Storage connection string + - `WebJob:QueueName` - The name of the queue to monitor + +3. Run the application: + + ```bash + dotnet run + ``` + +## Dependencies + +- Microsoft.Azure.WebJobs +- Microsoft.Azure.WebJobs.Extensions +- Microsoft.Azure.WebJobs.Extensions.Storage +- Microsoft.Extensions.Configuration.AzureAppConfiguration \ No newline at end of file diff --git a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Functions.cs b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Functions.cs index 3f00e2f0..5de71768 100644 --- a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Functions.cs +++ b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Functions.cs @@ -1,19 +1,18 @@ using Microsoft.Azure.WebJobs; using Microsoft.Extensions.Logging; -namespace WebJobHelloWorld +namespace WebJobHelloWorld; + +public class Functions { - public class Functions + public static void ProcessQueueMessage( + [QueueTrigger("%QueueName%")] string message, // Get queue name from config + ILogger logger) { - public static void ProcessQueueMessage( - [QueueTrigger("%QueueName%")] string message, // Get queue name from config - ILogger logger) - { - // - // Insert code to process the message here. - // + // + // Insert code to process the message here. + // - logger.LogInformation(message); - } + logger.LogInformation(message); } } diff --git a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs index 3a14d457..8cbbe403 100644 --- a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs +++ b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs @@ -1,67 +1,63 @@ using System; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.AzureAppConfiguration; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace WebJobHelloWorld; -namespace WebJobHelloWorld +class Program { - class Program + static void Main(string[] args) { - static void Main(string[] args) - { - var hostBuilder = new HostBuilder(); - hostBuilder.ConfigureHostConfiguration((config) => + var host = new HostBuilder() + .ConfigureHostConfiguration(config => { LoadConfiguration(config); - }); - hostBuilder.ConfigureWebJobs(b => - { - b.AddAzureStorageCoreServices(); - b.AddAzureStorage(); - }); - hostBuilder.ConfigureLogging((context, b) => - { - b.AddConsole(); - }); + }) + .ConfigureWebJobs(builder => + { + builder.AddAzureStorageQueues(); + }) + .ConfigureLogging(logging => + { + logging.AddConsole(); + }) + .Build(); + + host.Run(); + } - var host = hostBuilder.Build(); - using (host) - { - host.Run(); - } - } + private static void LoadConfiguration(IConfigurationBuilder configBuilder) + { + // + // This application attempts to connect to Azure App Configuration to retrieve Azure Blob Storage name, and Queue Name for the Azure Web Job. + // It reads the ConnectionString for the App Configuration Service from environment variables. + configBuilder.AddEnvironmentVariables(); - private static void LoadConfiguration(IConfigurationBuilder configBuilder) + var config = configBuilder.Build(); + if (string.IsNullOrEmpty(config["ConnectionString"])) { - // - // This application attempts to connect to Azure App Configuration to retrieve Azure Blob Storage name, and Queue Name for the Azure Web Job. - // It reads the ConnectionString for the App Configuration Service from environment variables. - configBuilder.AddEnvironmentVariables(); - - var config = configBuilder.Build(); - if (string.IsNullOrEmpty(config["ConnectionString"])) - { - throw new ArgumentNullException("Please set the 'ConnectionString' environment variable to a valid Azure App Configuration connection string and re-run this example."); - } + throw new ArgumentNullException("Please set the 'ConnectionString' environment variable to a valid Azure App Configuration connection string and re-run this example."); + } - configBuilder.AddAzureAppConfiguration(options => - { - options.Connect(config["ConnectionString"]) - .Use("WebJob:*") - .TrimKeyPrefix("WebJob:"); - }); + configBuilder.AddAzureAppConfiguration(options => + { + options.Connect(config["ConnectionString"]) + .Select("WebJob:*") + .TrimKeyPrefix("WebJob:"); + }); - config = configBuilder.Build(); + config = configBuilder.Build(); - if (string.IsNullOrEmpty(config["AzureWebJobsStorage"])) - { - throw new ArgumentNullException("AzureWebJobsStorage not found."); - } - else if (string.IsNullOrEmpty(config["QueueName"])) - { - throw new ArgumentNullException("QueueName not found."); - } + if (string.IsNullOrEmpty(config["AzureWebJobsStorage"])) + { + throw new ArgumentNullException("AzureWebJobsStorage not found."); + } + else if (string.IsNullOrEmpty(config["QueueName"])) + { + throw new ArgumentNullException("QueueName not found."); } } } diff --git a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/WebJobHelloWorld.csproj b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/WebJobHelloWorld.csproj index f21be24c..a340fa25 100644 --- a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/WebJobHelloWorld.csproj +++ b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/WebJobHelloWorld.csproj @@ -2,16 +2,18 @@ Exe - netcoreapp2.2 + net8.0 + enable + enable - - - - - - + + + + + + From fd199caaab0d3993f48434772a26317af4cfa3da Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 May 2025 01:05:17 +0000 Subject: [PATCH 3/6] Update to use DefaultAzureCredential for authentication Co-authored-by: zhenlan <10566826+zhenlan@users.noreply.github.com> --- .../WebJobs/WebJobHelloWorld/README.md | 20 +++++++++++++------ .../WebJobHelloWorld/Program.cs | 12 +++++++---- .../WebJobHelloWorld/WebJobHelloWorld.csproj | 1 + 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/examples/DotNetCore/WebJobs/WebJobHelloWorld/README.md b/examples/DotNetCore/WebJobs/WebJobHelloWorld/README.md index 9686256c..0f029eac 100644 --- a/examples/DotNetCore/WebJobs/WebJobHelloWorld/README.md +++ b/examples/DotNetCore/WebJobs/WebJobHelloWorld/README.md @@ -7,28 +7,35 @@ This sample demonstrates how to build a .NET 8 WebJobs application that uses Azu - [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) - Azure subscription with an App Configuration instance - Azure Storage account +- Azure identity with permissions to access the App Configuration instance ## How it works -This sample WebJob connects to Azure App Configuration to retrieve settings such as the Azure Storage connection string and queue name. It then listens to the specified queue for messages and logs them. +This sample WebJob connects to Azure App Configuration using DefaultAzureCredential to retrieve settings such as the Azure Storage connection string and queue name. It then listens to the specified queue for messages and logs them. ## Getting Started -1. Set the environment variable `ConnectionString` to your Azure App Configuration connection string: +1. Set the environment variable `AppConfigEndpoint` to your Azure App Configuration endpoint URI: ```bash # Windows - set ConnectionString= + set AppConfigEndpoint=https://.azconfig.io # Linux/macOS - export ConnectionString= + export AppConfigEndpoint=https://.azconfig.io ``` 2. Make sure you have the following configuration values set in your Azure App Configuration instance: - `WebJob:AzureWebJobsStorage` - Your Azure Storage connection string - `WebJob:QueueName` - The name of the queue to monitor -3. Run the application: +3. Ensure you have proper authentication set up for DefaultAzureCredential. This could be: + - Azure CLI login + - Visual Studio/Visual Studio Code authentication + - Environment variables for service principal credentials + - Managed Identity (when deployed to Azure) + +4. Run the application: ```bash dotnet run @@ -36,7 +43,8 @@ This sample WebJob connects to Azure App Configuration to retrieve settings such ## Dependencies +- Azure.Identity - Microsoft.Azure.WebJobs - Microsoft.Azure.WebJobs.Extensions -- Microsoft.Azure.WebJobs.Extensions.Storage +- Microsoft.Azure.WebJobs.Extensions.Storage.Queues - Microsoft.Extensions.Configuration.AzureAppConfiguration \ No newline at end of file diff --git a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs index 8cbbe403..69d787b7 100644 --- a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs +++ b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs @@ -1,4 +1,5 @@ using System; +using Azure.Identity; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.AzureAppConfiguration; @@ -33,18 +34,21 @@ private static void LoadConfiguration(IConfigurationBuilder configBuilder) { // // This application attempts to connect to Azure App Configuration to retrieve Azure Blob Storage name, and Queue Name for the Azure Web Job. - // It reads the ConnectionString for the App Configuration Service from environment variables. + // It reads the Endpoint URI for the App Configuration Service from environment variables. configBuilder.AddEnvironmentVariables(); var config = configBuilder.Build(); - if (string.IsNullOrEmpty(config["ConnectionString"])) + if (string.IsNullOrEmpty(config["AppConfigEndpoint"])) { - throw new ArgumentNullException("Please set the 'ConnectionString' environment variable to a valid Azure App Configuration connection string and re-run this example."); + throw new ArgumentNullException("Please set the 'AppConfigEndpoint' environment variable to a valid Azure App Configuration endpoint URI and re-run this example."); } configBuilder.AddAzureAppConfiguration(options => { - options.Connect(config["ConnectionString"]) + var endpoint = config["AppConfigEndpoint"] ?? + throw new ArgumentNullException("AppConfigEndpoint", "The AppConfigEndpoint environment variable cannot be null or empty."); + + options.Connect(new Uri(endpoint), new DefaultAzureCredential()) .Select("WebJob:*") .TrimKeyPrefix("WebJob:"); }); diff --git a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/WebJobHelloWorld.csproj b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/WebJobHelloWorld.csproj index a340fa25..90d47e6a 100644 --- a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/WebJobHelloWorld.csproj +++ b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/WebJobHelloWorld.csproj @@ -8,6 +8,7 @@ + From f63d5db4347ac6ccc042b1b393c460b482b43c3a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 May 2025 01:14:12 +0000 Subject: [PATCH 4/6] Update environment variable name to AppConfigurationEndpoint for consistency Co-authored-by: zhenlan <10566826+zhenlan@users.noreply.github.com> --- examples/DotNetCore/WebJobs/WebJobHelloWorld/README.md | 6 +++--- .../WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/DotNetCore/WebJobs/WebJobHelloWorld/README.md b/examples/DotNetCore/WebJobs/WebJobHelloWorld/README.md index 0f029eac..458f77bb 100644 --- a/examples/DotNetCore/WebJobs/WebJobHelloWorld/README.md +++ b/examples/DotNetCore/WebJobs/WebJobHelloWorld/README.md @@ -15,14 +15,14 @@ This sample WebJob connects to Azure App Configuration using DefaultAzureCredent ## Getting Started -1. Set the environment variable `AppConfigEndpoint` to your Azure App Configuration endpoint URI: +1. Set the environment variable `AppConfigurationEndpoint` to your Azure App Configuration endpoint URI: ```bash # Windows - set AppConfigEndpoint=https://.azconfig.io + set AppConfigurationEndpoint=https://.azconfig.io # Linux/macOS - export AppConfigEndpoint=https://.azconfig.io + export AppConfigurationEndpoint=https://.azconfig.io ``` 2. Make sure you have the following configuration values set in your Azure App Configuration instance: diff --git a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs index 69d787b7..b8ae0c62 100644 --- a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs +++ b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs @@ -38,15 +38,15 @@ private static void LoadConfiguration(IConfigurationBuilder configBuilder) configBuilder.AddEnvironmentVariables(); var config = configBuilder.Build(); - if (string.IsNullOrEmpty(config["AppConfigEndpoint"])) + if (string.IsNullOrEmpty(config["AppConfigurationEndpoint"])) { - throw new ArgumentNullException("Please set the 'AppConfigEndpoint' environment variable to a valid Azure App Configuration endpoint URI and re-run this example."); + throw new ArgumentNullException("Please set the 'AppConfigurationEndpoint' environment variable to a valid Azure App Configuration endpoint URI and re-run this example."); } configBuilder.AddAzureAppConfiguration(options => { - var endpoint = config["AppConfigEndpoint"] ?? - throw new ArgumentNullException("AppConfigEndpoint", "The AppConfigEndpoint environment variable cannot be null or empty."); + var endpoint = config["AppConfigurationEndpoint"] ?? + throw new ArgumentNullException("AppConfigurationEndpoint", "The AppConfigurationEndpoint environment variable cannot be null or empty."); options.Connect(new Uri(endpoint), new DefaultAzureCredential()) .Select("WebJob:*") From 61d1bb5dcc97fef517d2f7f6f8d6f93741be6bb5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 May 2025 19:27:25 +0000 Subject: [PATCH 5/6] Update package references to latest stable versions Co-authored-by: zhenlan <10566826+zhenlan@users.noreply.github.com> --- .../WebJobHelloWorld/WebJobHelloWorld.csproj | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/WebJobHelloWorld.csproj b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/WebJobHelloWorld.csproj index 90d47e6a..e2262b3e 100644 --- a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/WebJobHelloWorld.csproj +++ b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/WebJobHelloWorld.csproj @@ -8,13 +8,13 @@ - + - - - - + + + + From ffcc3cad8689252b57cd08e0a30ed7190be17efe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 May 2025 19:31:02 +0000 Subject: [PATCH 6/6] Add copyright headers to WebJobHelloWorld project Co-authored-by: zhenlan <10566826+zhenlan@users.noreply.github.com> --- .../WebJobs/WebJobHelloWorld/WebJobHelloWorld/Functions.cs | 5 ++++- .../WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Functions.cs b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Functions.cs index 5de71768..d2cc79ca 100644 --- a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Functions.cs +++ b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Functions.cs @@ -1,4 +1,7 @@ -using Microsoft.Azure.WebJobs; +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +// +using Microsoft.Azure.WebJobs; using Microsoft.Extensions.Logging; namespace WebJobHelloWorld; diff --git a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs index b8ae0c62..e3529264 100644 --- a/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs +++ b/examples/DotNetCore/WebJobs/WebJobHelloWorld/WebJobHelloWorld/Program.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +// +using System; using Azure.Identity; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Configuration;