Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Sign InSign Up

Softans

Softans Logo Softans Logo
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
Home/ Questions/Q 3910
Answered
Ghulam Nabi
Ghulam Nabi
Asked: November 25, 20222022-11-25T09:32:53+00:00 2022-11-25T09:32:53+00:00

Azure Functions – local development: How to respect environment in trigger annotation?

In a Function App that we develop locally in Visual Studio, we have two environments to run against: Test and Development.

Now, we have a local.settings.json and two respective environment-specific local.settings.<environment>.json which works totally fine – with one exception: The values used in the function trigger annotation.

They seem to be resolved before the actual process is even started and from local.settings.json, only.

It’s dotnet 6, v4, isolated process. The project is set up to read from local.settings.json and local.settings.<environment>.json.

The relevant files look like this:

lauchSettings.json

{
  "profiles": {
    "My.Project.Functions": {
      ...,
      "environmentVariables": {
        "AZURE_FUNCTIONS_ENVIRONMENT": "Test"
      }
    }
  }
}

local.settings.Test.json

{
    "myTopicName": "some-topic-for-test",
    "myServiceBusConnection": "Endpoint=sb://MyTestBusURI"
}

MyFunction.cs

public class MyFunction
{

    [Function(nameof(MyFunctionAsync))]
    public async Task MyFunctionAsync(
       [ServiceBusTrigger("%myTopicName%", Connection = "myServiceBusConnection")] // <-- error here
       MyMessageEntity myMessageEntity)
    {
        // resolving environment-specific values _here_ will work perfectly fine.
        await _someIrrelevantService.DoSomethingAsync(myMessageEntity);
    }
}

If we do not have myTopicName and myServiceBusConnection in local.settings.json but only in the environment specific settings, the app won’t start, complaining that the respective settings are not found.

We really would like to avoid having to copy around settings, making this tedious and error-prone.

I have been through a lot of Microsoft documentation, which unfortunately never speaks about environment specific settings files in local development. So, I am dreading this may not even be possible but:

Does anyone have an idea, how I can make the tooling respect the environment specific settings in the annotation? (“You cannot” would be a valid answer, so I can continue looking for workarounds without a bad conscience 🙂 )


As requested: We load configs like so:

return hostBuilder
           .ConfigureAppConfiguration((context, builder) =>
           {
               builder.SetBasePath(Directory.GetCurrentDirectory())
                      .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                      .AddJsonFile($"local.settings.{context.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true)
                      .AddEnvironmentVariables();
           })

Which is working fine but is irrelevant because it happens, after the annotation’s references are resolved.

azure functionsc++
  • 0
  • 1 1 Answer
  • 9 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

1 Answer

  • Voted
  • Oldest
  • Recent
  1. Best Answer
    Ghulam Nabi
    2022-11-25T09:33:47+00:00Added an answer on November 25, 2022 at 9:33 am

    {
    “IsEncrypted”: false,
    “Values”: {
    “FUNCTIONS_WORKER_RUNTIME”: “<language worker>”,
    “AzureWebJobsStorage”: “<connection-string>”,
    “MyBindingConnection”: “<binding-connection-string>”,
    “AzureWebJobs.HttpExample.Disabled”: “true”
    },
    “Host”: {
    “LocalHttpPort”: 7071,
    “CORS”: “*”,
    “CORSCredentials”: false
    },
    “ConnectionStrings”: {
    “SQLConnectionString”: “<sqlclient-connection-string>”
    }
    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • Popular
  • Answers
  • Ghulam Nabi

    Why are the British confused about us calling bread rolls ...

    • 5 Answers
  • Jerry

    Add file to native target programmatically via tuist/XcodeProj

    • 4 Answers
  • Ghulam Nabi

    Is this statement, “i see him last night” can be ...

    • 4 Answers
  • Ghulam Nabi
    Ghulam Nabi added an answer To resolve the NullPointerException, you need to identify the variable… March 15, 2023 at 8:25 am
  • Ghulam Nabi
    Ghulam Nabi added an answer You can replace the PnP code in your Azure Function… February 13, 2023 at 7:11 am
  • Ghulam Nabi
    Ghulam Nabi added an answer You can use the $match stage in the aggregate pipeline… February 10, 2023 at 6:20 am

Trending Tags

android c++ cypress flutter java javascript python selenium testng webdriver

Top Members

Robert

Robert

  • 3 Questions
  • 1k Points
Luci

Luci

  • 5 Questions
  • 1k Points
Kevin O Brien

Kevin O Brien

  • 2 Questions
  • 1k Points

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Softans

Softans is a social questions & Answers Engine which will help you establish your community and connect with other people.

About Us

  • Blog
  • Jobs
  • About Us
  • Meet The Team
  • Contact Us

Legal Stuff

Help

Follow

© 2021 Softans. All Rights Reserved
With Love by Softans.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.