使用 Azure Functions v2 的 IWebJobsStartup
IWebJobsStartup with Azure Functions v2
我正在尝试通过 visual studio 和 CLI 使用 V2 运行time 创建一个 azure 函数。但是当我 运行 它时,我看到以下错误:
[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.).
以下是azure函数运行时间和核心工具版本
Azure 函数核心工具 (2.0.3)
函数运行时版本:2.0.12115.0
我还安装了服务总线扩展
我也尝试过通过 CLI 安装扩展。以下是 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>
注意 - 这是开箱即用的模板,未进行任何更改。
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.0.1" />
请删除此包引用并清理项目,它已在 Microsoft.NET.Sdk.Functions
中导入用于 VS 开发。再次导入它可能会导致您所看到的构建错误。
更新
由于您在构建的资产中没有看到 function.json
,恐怕您这边的 Microsoft.NET.Sdk.Functions
有问题,无法将 .cs 文件中的触发器属性构建到 function.json
。我的建议是
- 删除函数SDK
%userprofile%\.nuget\packages\microsoft.net.sdk.functions
。
- 删除 VS 使用的函数 CLI
%localappdata%\AzureFunctionsTools
。
- 删除 VS 使用的模板引擎
%userprofile%\.templateengine
。
- 重新启动 VS 并创建一个新的 Function 项目,在 creation/template 对话框的底部,参见
Making sure all templates are up to date
。等到它变成 Updates are ready
。
- 单击
Refresh
。
为了以防万一您需要检查,我在 VS 中使用服务总线队列触发器模板。代码如下,.csproj 与没有 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}");
}
}
}
以及[Functionproject]\bin\Debug\netstandard2.0
中的文件夹结构。
我正在尝试通过 visual studio 和 CLI 使用 V2 运行time 创建一个 azure 函数。但是当我 运行 它时,我看到以下错误:
[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.).
以下是azure函数运行时间和核心工具版本
Azure 函数核心工具 (2.0.3) 函数运行时版本:2.0.12115.0
我还安装了服务总线扩展
我也尝试过通过 CLI 安装扩展。以下是 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>
注意 - 这是开箱即用的模板,未进行任何更改。
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.0.1" />
请删除此包引用并清理项目,它已在 Microsoft.NET.Sdk.Functions
中导入用于 VS 开发。再次导入它可能会导致您所看到的构建错误。
更新
由于您在构建的资产中没有看到 function.json
,恐怕您这边的 Microsoft.NET.Sdk.Functions
有问题,无法将 .cs 文件中的触发器属性构建到 function.json
。我的建议是
- 删除函数SDK
%userprofile%\.nuget\packages\microsoft.net.sdk.functions
。 - 删除 VS 使用的函数 CLI
%localappdata%\AzureFunctionsTools
。 - 删除 VS 使用的模板引擎
%userprofile%\.templateengine
。 - 重新启动 VS 并创建一个新的 Function 项目,在 creation/template 对话框的底部,参见
Making sure all templates are up to date
。等到它变成Updates are ready
。 - 单击
Refresh
。
为了以防万一您需要检查,我在 VS 中使用服务总线队列触发器模板。代码如下,.csproj 与没有 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}");
}
}
}
以及[Functionproject]\bin\Debug\netstandard2.0
中的文件夹结构。