How to create a minimum Aspire project that uses Service Bus and Event Hub emulators with a Function App.
This was tested with .net10
Assuming the dotnet CLI is already installed.
mkdir test; cd test
dotnet new install Aspire.ProjectTemplates
dotnet new aspire-starter
dotnet new gitignore
dotnet sln migrate; rm *.sln
dotnet dev-certs https --trust
dotnet run --project .\test.AppHost\test.AppHost.csprojAssuming the Aspire CLI is already installed.
aspire update --self
aspire update
aspire add azure-servicebus
aspire add azure-eventhubsUpdate the AppHost.cs to add Event Hubs and Service Bus emulators.
var eventHubs =
builder.AddAzureEventHubs("event-hubs")
.RunAsEmulator();
eventHubs.AddHub("messages");
// The name given to the AddAzureServiceBus() method must match the
// name expected by the function's trigger's 'Connection' parameter.
var serviceBus =
builder.AddAzureServiceBus("service-bus")
.RunAsEmulator();
serviceBus.AddServiceBusQueue("servicebus-queue");winget install Microsoft.Azure.FunctionsCoreTools
aspire add azure-functions
mkdir test.Function; cd .\test.Function\
func init --worker-runtime dotnet-isolated --target-framework net10.0
func new --template "ServiceBusQueueTrigger" --name "TestServiceBusQueueTrigger"
cd ..
dotnet reference add .\test.ServiceDefaults\test.ServiceDefaults.csproj --project .\test.Function\test_Function.csproj
dotnet reference add .\test.Function\test_Function.csproj --project .\test.AppHost\test.AppHost.csproj
dotnet sln add .\test.Function\test_Function.csprojThe connection and the queue names set in the AppHost must be used in the trigger.
[ServiceBusTrigger("servicebus-queue", Connection = "service-bus")]The function's Program should call the ServiceDefaults.
builder.AddServiceDefaults();In AppHost.cs.
builder.AddAzureFunctionsProject<Projects.test_Function>("functions")
.WithReference(serviceBus)
.WaitFor(serviceBus)
.WithReference(eventHubs)
.WaitFor(eventHubs);dotnet run --project .\test.AppHost\test.AppHost.csproj