【问题标题】:Azure Function startup's Configure not being called未调用 Azure Function 启动的配置
【发布时间】:2022-01-18 18:19:48
【问题描述】:

我正在尝试在 .NET 5 (VS 2022) 中的 Azure Function 项目中创建非静态函数,但未调用 Startup Configure 方法。

这是我的入门课程

[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

【问题讨论】:

  • 如果该类被标记为公开会怎样?
  • @PeterBons 已经试过了,不行。
  • 你的host.json是什么样的?
  • 还有你的实际功能
  • 哦,你在 Azure 中的设置?我想你的意思是它不能在 Azure 中工作,而不是在你的本地机器上?

标签: c# azure .net-core azure-functions asp.net-core-5.0


【解决方案1】:

我已尝试按照以下步骤重现您遇到的相同问题:

  1. 在 VS2022 中创建了 Azure Functions(堆栈:.Net5-v3)。
  2. 在项目中添加Microsoft.Net.Sdk.functions之前,已经构建成功了。

  1. Microsoft.Net.Sdk.functions添加到项目后,运行到同样的问题MSB4062错误如下:

通过引用这些 SO Thread1Thread2,删除 Microsoft.Net.Sdk.functions 将解决编译问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-23
    • 2016-10-26
    相关资源
    最近更新 更多