Azure Function Folder Structure

Azure Function Folder Structure

Well, here we will discuss the Azure Function Folder Structure. It would be best to understand it before creating Azure Functions.

Azure Function Folder Structure

Once you create an Azure Function Project using Visual Studio 2019, You will get the Azure Function Project Structure below.

Azure Function Folder Structure

If you click on the Project name, i.e., TestAzureFunction, in my case, that is the .csproj file that contains all the configurations for your Azure Function project. This file contains the code below

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.36" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Dependencies contain all the packages(DLLs) and SDKs needed for your Azure Function Project. You will expand that you can see many dlls referred to your Azure Function Project. Below are a few of them

Microsoft.NET.Sdk.Functions
Microsoft.Azure.Webjobs
NewtonSoft.json

Function1.cs file is the main class file that contains the Azure Function code. If you want to modify the Azure Function logic based on your business requirement, then you must modify the Azure function code in this file.

The file will look like below

azure function project structure

The next file is the host.json file, which contains all the settings or configuration options that affect all the Azure functions within that Azure Function App. If you want to apply any configuration property changes, this is the file you must change.

The default host.json file contains the below code

{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            }
        }
    }
}

Next, coming to the local.settings.json file, you can keep the application settings value that we get from the Azure Portal. It contains the configurations below

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet"
    }
}

One important thing to note down here is, local.settings.json file changes are for local use only, you can consider them for development purposes only. Once you will deploy the Azure Function to Azure. You will not get the reference for this file. This is very important to remember.

If you are referring to any of the application settings from the local.settings.json file, then Once you deploy the Azure Function to the Azure Portal, Make sure to do the same application settings changes manually in the Azure Portal since you will not get the reference of this file in Azure or else your Azure Function will not work properly.

Final Thoughts

In this Azure article, we discussed Azure Functions Folder Structure. Thanks for reading this article !!!