avatarWouter

Summary

To resolve the issue of a function app ignoring settings within local.settings.json when running on a local machine, ensure that the file is properly copied to the output directory by adding a specific entry to the .csproj file, and remember to rebuild the project after any changes.

Abstract

The article addresses a common problem faced by developers working with Azure function apps using Visual Studio. Specifically, it provides a solution for when the application ignores the settings provided in the local.settings.json file during local execution. To rectify this, it suggests modifying the project's .csproj file by including instructions to copy the settings file to the output directory, which is crucial for the function app to read it. The article instructs adding an XML block with the CopyToOutputDirectory and CopyToPublishDirectory tags, set to "Always" and "Never" respectively, ensuring the file is picked up during local runs, and not published to live environments. It also informs that these changes take effect only after rebuilding the project, and presents the solution as a hopeful fix for others who may encounter the same issue.

Opinions

  • The article suggests that the local.settings.json being ignored by the function app is a known struggle.
  • It mentions the use of Visual Studio as the development environment and provides a solution within the context of this IDE.
  • The author shares a personal experience and positions the solution as one that they discovered and believe to be effective.
  • The article implies that this is a recurring problem, as it is referred to as a "method" for future reference by the author.
  • There is an emphasis on the importance of rebuilding the project after making changes to the settings file.
  • The author's hope is expressed that this solution will be useful to others facing the same issue.

Quickfix Azure function: local.settings.json not working

Here is another post for future me. What to do if your local.settings.json file in your function app are being ignored

I was struggling with my settings when trying to run my function app on my local computer. I was using Visual Studio and my function app had a local.settings.json file with some settings in it. But for some reason these settings were ignored.

Copy the local.settings.json file to the output directory

In your csproj file add this line:

 <None Update="local.settings.json">
  <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  <CopyToPublishDirectory>Never</CopyToPublishDirectory>
 </None>

You can also use the visual editor in Visual Studio. In the properties tab of your local.settings.json file make sure the Copy to Output Directory is set to copy always.

This will make sure the local.settings.json file gets copied to the output folder and will be picked up by your function app.

Remember that you must rebuild your project if you make any changes to the settings.

If you are encountering the same issue, I hope this method fixes it for you.

Azure Function App
Visual Studio
Local Settings Json
Json
Appsettings
Recommended from ReadMedium