Search code examples
azureazure-functionsazure-functions-runtimeazure-functions-core-tools

IWebJobsStartup with Azure Functions v2


I am trying to create an azure function with V2 runtime through visual studio and CLI. But when i run it, i see the following error:

[9/30/2018 3:11:06 PM] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).

Following is the azure function run time and core tool version

Azure Functions Core Tools (2.0.3) Function Runtime Version: 2.0.12115.0

Also i have installed the service bus extension

enter image description here

I have also tried to install the extension through CLI too. Following is the project.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <AzureFunctionsVersion>V2</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="3.0.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.0.1" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.22" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Note - This is out of the box template and no changes have been made.


Solution

  • <PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.0.1" />
    

    Please remove this package reference and clean the project, it has been imported in Microsoft.NET.Sdk.Functions for VS development. Import it again may cause building error like you have seen.

    Update

    Since you don't see function.json in built assets, I am afraid there is something wrong with Microsoft.NET.Sdk.Functions on your side, which fails to build trigger attribute in .cs file to function.json. My suggestion is

    1. Delete Function SDK %userprofile%\.nuget\packages\microsoft.net.sdk.functions.
    2. Delete Function CLI using by VS %localappdata%\AzureFunctionsTools.
    3. Delete template engine consumed by VS %userprofile%\.templateengine.
    4. Restart VS and create a new Function project, at the bottom of the creation/template dialog, see Making sure all templates are up to date. Wait until it changes to Updates are ready. enter image description here enter image description here
    5. Click Refresh.

    Just in case you need to check, I use the Service Bus queue trigger template in VS. The code is as below, .csproj is same as the one in question without Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.

        using Microsoft.Azure.WebJobs;
        using Microsoft.Azure.WebJobs.Host;
        using Microsoft.Extensions.Logging;
    
        namespace FunctionApp1
        {
            public static class Function1
            {
                [FunctionName("Function1")]
                public static void Run([ServiceBusTrigger("myqueue", Connection = "MyConnection")]string myQueueItem, ILogger log)
                {
                    log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
                }
            }
        }
    

    And the folder structure in [Functionproject]\bin\Debug\netstandard2.0.

    enter image description here