我正在尝试在 .NET 5 (VS 2022) 中的 Azure Function 项目中创建非静态函数,并且
Startup
配置方法未被调用。
这是我的入门课程
[assembly: FunctionsStartup(typeof(AuthenticationGateway.Functions.Startup))]
namespace AuthenticationGateway.Functions
{
class Startup : FunctionsStartup //public or not, still does not get called.
{
public override void Configure(IFunctionsHostBuilder builder)
{
//break point here never gets hit...
}
}
}
这是有问题的函数:
namespace AuthenticationGateway.Functions
{
public class CreationConnection
{
private AuthenticationGatewayContext Context { get; set; }
public CreationConnection(AuthenticationGatewayContext context)
{
Context = context;
}
[Function("CreationConnection")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequestData req,
FunctionContext executionContext)
{
var response = req.CreateResponse(HttpStatusCode.OK);
return response;
}
}
}
我尝试对
Configure
中的所有代码进行注释,以防出现问题,但也不起作用。也尝试将启动类标记为public
,不行。
以下是相关项目的依赖项
它们不是项目在创建 Azure Function 项目时具有的默认依赖项,但当我尝试其他解决方案来解决问题时,它导致我插入这些依赖项。
这是启动项目时控制台所说的内容:
Azure Functions 核心工具核心工具版本:3.0.3904 提交 哈希:c345f7140a8f968c5dbc621f8a8374d8e3234206(64 位)函数 运行时版本:3.3.1.0
我错过了什么吗?
编辑:我已恢复到以下依赖项,因为之前的依赖项已实现,因此在项目中找不到任何功能。
在this页面上,它说必须安装以下依赖项:
Microsoft.Azure.Functions.Extensions
Microsoft.NET.Sdk.Functions package version 1.0.28 or later
Microsoft.Extensions.DependencyInjection (currently, only version 3.x and earlier supported)
我已经这样做了,除了最后一个,因为它似乎与 .NET 5 不兼容。此外,该项目现在无法构建:
error MSB4062: The "GenerateFunctionMetadata" task could not be loaded from the assembly
就我而言,我缺少命名空间上的程序集注释:
[assembly: FunctionsStartup(typeof(MyApp.Functions.Startup))] // this is what was missing
namespace MyApp.Functions;
internal class Startup : FunctionsStartup
{
public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
{
// app configure stuff
}
public override void Configure(IFunctionsHostBuilder builder)
{
// configure stuff
}
}