title: Setting Azure Functions app's base directory wtih Azure Function app 2.x
body: <p>I need to set a Azure Functions app's base directory to the <code>azurewebjobsscriptroot</code> like below, but got exception</p>
  
  <pre><code>var config = new ConfigurationBuilder()
      .SetBasePath("%HOME%\site\wwwroot")   //error
      .AddJsonFile("Settings.json", optional: true, reloadOnChange: true)
      .AddEnvironmentVariables()
      .Build();
  </code></pre>
  
  <blockquote>
    <p>System.ArgumentException : The path must be absolute. Parameter name:
    root    at
    Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String
    root,ExclusionFilters filters)    at
    Microsoft.Extensions.Configuration.FileConfigurationExtensions.SetBasePath(IConfigurationBuilder
    builder,String basePath)</p>
  </blockquote>
  
  <p>Azure function 2.x</p>
  
  <p>VS 2017</p>
  
  <p><a href="https://stackoverflow.com/questions/55093404/executioncontext-is-null-to-non-function-methods-via-ioc-alternative-to-executi">ExecutionContext is null to non-function methods via IoC, alternative to ExecutionContext.FunctionAppDirectory</a></p>
  
  <p><a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-app-settings#azurewebjobsscriptroot" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/azure-functions/functions-app-settings#azurewebjobsscriptroot</a></p>