You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Framework 4.8 Azure Function V1迁移ServiceBus扩展后找不到作业函数

.NET Framework 4.8 Azure Function V1 初始化ServiceBus扩展的正确方式

核心结论

不需要将类库项目转为控制台程序,通过添加启动配置类即可完成ServiceBus扩展的初始化,解决"No job functions found"错误。

具体步骤

  • 添加启动配置类
    在项目中新建Startup.cs类,实现IWebJobsStartup接口,并通过程序集特性注册启动逻辑,代码示例:

    using Microsoft.Azure.WebJobs;
    using Microsoft.Azure.WebJobs.Hosting;
    using Microsoft.Azure.WebJobs.Extensions.ServiceBus;
    
    [assembly: WebJobsStartup(typeof(YourFunctionNamespace.Startup))]
    namespace YourFunctionNamespace
    {
        public class Startup : IWebJobsStartup
        {
            public void Configure(IWebJobsBuilder builder)
            {
                // 注册ServiceBus扩展
                builder.AddServiceBus();
            }
        }
    }
    

    这里使用builder.AddServiceBus()而非旧的config.UseServiceBus(),是因为新的Extensions包基于IWebJobsBuilder提供扩展注册。

  • 匹配兼容的包版本
    确保安装的Microsoft.Azure.WebJobs.Extensions.ServiceBus版本适配.NET Framework 4.8和Function V1,推荐使用3.x系列稳定版本(如3.0.0),高版本(4.x+)仅支持.NET Core/.NET 5+环境。

  • 修正函数触发属性
    替换旧弃用包中的ServiceBusTrigger,改用新扩展包的属性,确保命名空间正确,示例:

    using Microsoft.Azure.WebJobs;
    using Microsoft.Azure.WebJobs.Extensions.ServiceBus;
    using Microsoft.Extensions.Logging;
    
    namespace YourFunctionNamespace
    {
        public static class TopicTriggerFunction
        {
            [FunctionName("TopicMessageProcessor")]
            public static void ProcessMessage(
                [ServiceBusTrigger("your-topic", "your-subscription", Connection = "ServiceBusConn")] string messageContent,
                ILogger log)
            {
                log.LogInformation($"处理消息: {messageContent}");
            }
        }
    }
    
  • 验证连接字符串配置
    本地运行时确保local.settings.json中存在对应连接字符串配置:

    {
        "IsEncrypted": false,
        "Values": {
            "AzureWebJobsStorage": "UseDevelopmentStorage=true",
            "ServiceBusConn": "你的Service Bus连接字符串"
        }
    }
    

    部署到Azure后,在应用服务的"配置"中添加同名连接字符串设置。

内容的提问来源于stack exchange,提问作者jlathem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 20:40:29