c# - .net5 上的函数 : No job functions found. 尝试将您的作业类和方法公开

标签 c# azure azure-functions .net-5

我正在探索在 .net5 上运行函数应用程序。这是我到目前为止所拥有的。

这是新的 Program 类,它取代了 Startup 类:

public static class Program
{
    private static Task Main(string[] args)
    {
        IHost host = new HostBuilder()
            .ConfigureAppConfiguration(configurationBuilder => { configurationBuilder.AddCommandLine(args); })
            .ConfigureFunctionsWorkerDefaults()
            .ConfigureServices(services =>
            {
                // Add Logging
                services.AddLogging();

                // Add HttpClient
                services.AddHttpClient();

                // Add Custom Services
            })
            .Build();

        return host.RunAsync();
    }
}

我还有这个非常简单的 HTTP 触发函数:

public sealed class StorageAccountsFunction
{
    private readonly ILogger<StorageAccountsFunction> m_logger;

    public StorageAccountsFunction(ILogger<StorageAccountsFunction> logger)
    {
        m_logger = logger;
    }

    [Function("v1-get-storage-accounts")]
    public HttpResponseData GetAsync
    (
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "api/v1/storage-accounts")] 
        HttpRequestData httpRequestData, 
        FunctionContext context
    )
    {
        return httpRequestData.CreateResponse(System.Net.HttpStatusCode.OK);
    }
}

我修改了 local.settings.json 以指示该函数必须在隔离模式下运行:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
    }
}

我使用以下参数启动该函数:

func host start --pause-on-error --verbose --dotnet-isolated-debug

问题

当我启动应用程序时,我收到此警告消息:

[2021-07-08T13:13:54.813Z] Loading functions metadata
[2021-07-08T13:13:54.814Z] Reading functions metadata
[2021-07-08T13:13:54.815Z] 0 functions found
[2021-07-08T13:13:54.841Z] 0 functions loaded
[2021-07-08T13:13:54.868Z] Generating 0 job function(s)
[2021-07-08T13:13:54.898Z] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

我相信我已经遵循了instructions在隔离进程中的 .net5 上运行函数时。我错过了什么?

更新

以下是版本信息:

Core Tools Version:       3.0.3568 Commit hash: e30a0ede85fd498199c28ad699ab2548593f759b  (64-bit)
Function Runtime Version: 3.0.15828.0

最佳答案

我不是 100% 确定罪魁祸首是什么,但我现在已经开始工作了。我已将 .Net 更新为最新的 net5 SDK (5.0.301)。

然后我意识到我的 local.settings.json 文件缺少一些信息,我认为最重要的是 FUNCTIONS_EXTENSION_VERSION 字段:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
        "FUNCTIONS_EXTENSION_VERSION": "~3"
    },
    "Host": {
        "LocalHttpPort": 7072,
        "CORS": "*"
    }
}

这是输出:

[2021-07-10T12:53:30.478Z] EnvironmentVariable FUNCTIONS_WORKER_RUNTIME: dotnet-isolated
[2021-07-10T12:53:30.478Z] EnvironmentVariable FUNCTIONS_WORKER_RUNTIME_VERSION: 
[2021-07-10T12:53:30.478Z] Added WorkerConfig for language: dotnet-isolated
[2021-07-10T12:53:30.479Z] Reading functions metadata
[2021-07-10T12:53:30.480Z] 0 functions found
[2021-07-10T12:53:30.489Z] 1 functions loaded
[2021-07-10T12:53:30.506Z] Adding Function descriptor provider for language dotnet-isolated.
[2021-07-10T12:53:30.508Z] Creating function descriptors.
[2021-07-10T12:53:30.563Z] Function descriptors created.
[2021-07-10T12:53:30.572Z] Generating 1 job function(s)

更新

我最终遇到了同样的问题,需要我添加 Microsoft.Azure.Functions.Worker.Sdk 包并更新 .csproj 文件以包含以下内容行:

<OutputType>Exe</OutputType>
    

关于c# - .net5 上的函数 : No job functions found. 尝试将您的作业类和方法公开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68303221/

相关文章:

c# - 如何使用 Linq Query 检索数据

c# - 如何跟踪异步/等待任务是否正在运行

azure - 尝试更新 Azure 表存储时出现 "One of the request inputs not valid"错误

c# - Azure Function 停止工作 - 无法加载类型 'Microsoft.Azure.WebJobs.BlobTriggerAttribute'

c# - WebBrowser 未正确显示页面

C# - 修改 DaraGridView 中 column1 的值并将它们放入新列

c# - 如何让异步任务等待结果以进行进一步操作xamarin表单?

Azure 容器实例与 Azure Functions

azure - 在azure函数应用程序中使用c#代码覆盖host.json文件的functiontimeout

c# - 如何确保所有 C# Azure 函数触发器都具有有效的依赖项注入(inject)?