I need to get the directory of the folder for when the Azure Function is published. That directory will look something like homesitewwwroot
. I have learned a good practice to get the folder is by using the ExecutionContext.FunctionDirectory
to recieve the directory. So I used this in the code like following:
var context = new ExecutionContext();
_applicationDirectory = context.FunctionAppDirectory;
var config = new ConfigurationBuilder()
.SetBasePath(_applicationDirectory)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build();
I tried to publish and test this, but it returns null
.
Does anyone have any suggestions on how to recieve my directory so I can set the base path to the currenct directory.
I have so far tried the code I provided just above. I have read a few StackOverFlows suggestion aswell, but without luck. Some suggest to use the FunctionAppDirectory
instead, but this resulted in the same issue.
Regarding debugging on Azure Portal, neither the Logs or Live Metrics provides anything else than the null exception.
2
Answers
I found a solution to the problem. The way I first thought was the correct possible way, is not the way to do it. By using the following code, I am able to recive the folder
Chomewwwroot
:I tried in my environment and got the below results:
I tried the below C# with logging method to get my Function Directory:-
Local Output:-
Then I published this function to my FunctionApp in Azure portal and Tested the function, I got the results below:-
Portal Output:-