【发布时间】:2022-01-25 09:19:46
【问题描述】:
我已经通过 VS Code 创建了 Azure Functions Http Trigger (C#)。
我遇到了一些命名空间错误,我试图通过安装几个包(如 Azure WebJobs、Azure WebJobs Extensions、System Component DataAnnotation 包)来解决这些错误,但错误并没有发生。
错误出现在这张图片中 - Click on Me!
文本格式错误: 对于这一行:
[Queue("orders")] IAsyncCollector<Order> orderQueue,
错误:
The type or namespace name 'QueueAttribute' could not be found (are you missing a using directive or an assembly reference?) [pluralsightfuncs]csharp(CS0246)
The type or namespace name 'Queue' could not be found (are you missing a using directive or an assembly reference?) [pluralsightfuncs]csharp(CS0246)
对于这一行:
[Table("orders")] IAsyncCollector<Order> orderTable,
错误:
The type or namespace name 'TableAttribute' could not be found (are you missing a using directive or an assembly reference?) [pluralsightfuncs]csharp(CS0246)
The type or namespace name 'Table' could not be found (are you missing a using directive or an assembly reference?) [pluralsightfuncs]csharp(CS0246)
代码在https://github.com/licjapodaca/pluralsightfuncs/blob/master/OnPaymentReceived.cs中提供
我的 .csproj 代码:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.30" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="4.0.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
【问题讨论】:
-
你需要使用
Microsoft.Azure.WebJobs.Extensions.Storage.Queues包 -
谢谢@Chetan,有时 Storage 包使用 Queue 和 table 属性,但有时每个属性都要求编写相关的包,如队列等。
标签: c# .net visual-studio-code azure-functions