1
votes

I try to publish Azure Function v.2, but I get an error:

The function runtime is unable to start. Microsoft.Extensions.Configuration.FileExtensions: The configuration file 'local.settings.json' was not found and is not optional. The physical path is 'D:\Program Files (x86)\SiteExtensions\Functions\2.0.12961\32bit\local.settings.json'.

I have the following configuration:

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

and I see this file in Kudu.

How to solve it?

ADDED:

I tried to create another file, named config.json:

{
  "FtpSettings": {
    "FtpServer": "ftp://address/out",
    "FtpLogin": "login",
    "FtpPassword": "pass"
  }
}

then try to read it:

        var config = new ConfigurationBuilder()
            .AddJsonFile("config.json", optional: true, reloadOnChange: true)
            .AddEnvironmentVariables()
            .Build();

        builder.Services.AddTransient<FtpService.IFtpService>(s => new FtpService.Core.FtpService(
            address: config.GetSection("FtpSettings:FtpServer").Value,
            username: config.GetSection("FtpSettings:FtpLogin").Value,
            password: config.GetSection("FtpSettings:FtpPassword").Value
            ));

so, my Startup class is:

[assembly: FunctionsStartup(typeof(FunctionAppEfsGetFilesFromFtp.Startup))]
namespace FunctionAppEfsGetFilesFromFtp
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var config = new ConfigurationBuilder()
                .AddJsonFile("config.json", optional: true, reloadOnChange: true)
                .AddEnvironmentVariables()
                .Build();

            builder.Services.AddTransient<FtpService.IFtpService>(s => new FtpService.Core.FtpService(
                address: config.GetSection("FtpSettings:FtpServer").Value,
                username: config.GetSection("FtpSettings:FtpLogin").Value,
                password: config.GetSection("FtpSettings:FtpPassword").Value
                ));
        }
    }
}

but it can't be read too

1
Do you have a startup class in your function?Ivan Yang
Can yuo show the code of your function start class?Cindy Pau
@IvanYang addedOleg Sh

1 Answers

1
votes

According to the docs:

By default, these settings are not migrated automatically when the project is published to Azure.

So local.settings.json is not included in the deployment process. The suggested way is to use the Environment variables. A workaround is to name the file something else and read the file in from path and parse it as json object.