gpt4 book ai didi

Azure 函数发布

转载 作者:行者123 更新时间:2023-12-03 02:43:20 25 4
gpt4 key购买 nike

我尝试发布 Azure Function v.2,但收到错误:

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'.

我有以下配置:

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

我在 Kudu 中看到了这个文件。

如何解决?

添加:

我尝试创建另一个文件,名为 config.json:

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

然后尝试阅读它:

        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
));

所以,我的 Startup 类是:

[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
));
}
}
}

但也无法读取

最佳答案

根据docs :

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

因此 local.settings.json 不包含在部署过程中。建议的方法是使用环境变量。解决方法是将文件命名为其他名称,然后从路径读取文件并将其解析为 json 对象。

关于Azure 函数发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59958400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com