【发布时间】:2020-02-04 05:32:48
【问题描述】:
我尝试发布 Azure Function v.2,但出现错误:
函数运行时无法启动。 Microsoft.Extensions.Configuration.FileExtensions:配置 找不到文件“local.settings.json”,不是可选的。这 物理路径是 '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
));
}
}
}
但也读不出来
【问题讨论】:
-
你的函数中有启动类吗?
-
可以显示你的函数启动类的代码吗?
-
@IvanYang 添加了
标签: azure azure-functions azure-function-app