代码之家  ›  专栏  ›  技术社区  ›  Gurpreet Singh

IWebJobsStartup with Azure功能v2

  •  3
  • Gurpreet Singh  · 技术社区  · 7 年前

    下面是azure函数运行时和核心工具版本

    函数运行时版本:2.0.12115.0

    enter image description here

    我也尝试过通过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>
    

    1 回复  |  直到 7 年前
        1
  •  2
  •   Jerry Liu Phantom    7 年前
    <PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.0.1" />
    

    Microsoft.NET.Sdk.Functions 用于VS开发。再次导入它可能会导致生成错误,如您所见。

    既然你看不见 function.json 内建资产,恐怕出了问题 在您这边,它无法在.cs文件中构建触发器属性 . 我的建议是

    1. 删除函数SDK %userprofile%\.nuget\packages\microsoft.net.sdk.functions .
    2. 用VS删除函数CLI %localappdata%\AzureFunctionsTools
    3. 删除VS使用的模板引擎 %userprofile%\.templateengine .
    4. 重新启动VS并创建一个新的函数项目,在creation/template对话框的底部,请参见 Making sure all templates are up to date Updates are ready . enter image description here enter image description here
    5. 点击 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 .

    enter image description here

    推荐文章