【问题标题】:Azure Functions Not Generating extensions.jsonAzure 函数不生成 extensions.json
【发布时间】:2018-09-17 20:26:32
【问题描述】:

我有一个由 ServiceBus 和 BlobStorage 触发的具有多个功能的 Azure Functions 项目。

他们已经构建和部署到 azure fine 几个月了。
最近发生了一些事情,当您单击时,他们不再从我的构建机器部署,在 Azure 中出现错误函数Error: The binding type(s) 'blobTrigger' are not registered.
不过,它仍然可以从我的开发机器上正常部署。他们正在使用 WEBSITE_RUN_FROM_ZIP 来部署代码本身。

我从我的开发机器和构建机器中提取了发布目录,看起来文件extensions.json 正在本地生成,但不在构建机器上,以及不存在的空本地化文件夹构建机器和大约 10mb 的大小差异,我还无法解释。
Azure Functions 的目标是 .Net Standard 2.0。检查 .Net 版本,.Net 核心在构建和开发机器上是相同的版本。

生成此文件的原因是什么?

【问题讨论】:

    标签: azure azure-functions .net-standard-2.0


    【解决方案1】:

    按照this Github comment 中的建议,我已经能够解决这个问题。

    基本上有时您必须包含一个额外的依赖项才能让 msbuild/visual studio 运行构建后步骤并生成您的扩展文件。
    Microsoft.Azure.Webjobs.Script.ExtensionsMetadataGenerator 添加为您的函数项目的依赖项,它应该始终(到目前为止)正确构建您的发布目录。

    像往常一样,留下问题让别人告诉我们为什么需要这样做。

    【讨论】:

    • 明确一点:依赖项是一个 NuGet 包,需要作为依赖项安装。
    【解决方案2】:

    其中一个可能的原因可能是 Azure Functions v2.0 的更新

    这可以解释突然的变化导致您提到的功能出现错误,这些功能直到几个月前才起作用。

    看看这个问题 https://github.com/Azure/azure-functions-host/issues/3363#issuecomment-417926456

    和你的很相似。

    v2.0 的一个变化是在使用存储相关的触发器时需要引用存储扩展

    在适当的地方引用存储扩展如果你有与 Azure 存储 (queue/tables/blob) 一起使用的函数 触发器、输入绑定或输出绑定,您需要参考 新的 Microsoft.Azure.WebJobs.Extensions.Storage 扩展。

    这是一个记录所有重大更改的链接 - Azure Functions Runtime 2.0.12050-alpha breaking changes notice

    【讨论】:

    • 谢谢,仔细研究这些。我相信该应用程序已经迁移到 beta 版本,因为它可以从开发机器上很好地打包和部署。只需要弄清楚我的构建机器缺少哪些新库。
    【解决方案3】:

    找出它为什么不起作用的最佳方法是在 Visual Studio 中打开诊断日志,然后进行构建。

    然后,在你构建之后,你可以搜索单词“extensions.json”

    这将是这样开始的:

    2>  Task "GenerateFunctionsExtensionsMetadata"
    2>    Task Parameter:SourcePath=F:\git\clients\hbti\Portal\hbti-web-master\HBTI.ServiceTech.AzureFunctions\bin\Debug\netcoreapp3.1\bin
    2>    Task Parameter:OutputPath=F:\git\clients\hbti\Portal\hbti-web-master\HBTI.ServiceTech.AzureFunctions\bin\Debug\netcoreapp3.1\bin
    2>    Extensions generator working directory: 'C:\Users\jsgou\.nuget\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\1.1.8\tools\net46\..\netstandard2.0\generator'
    2>    Extensions generator path: 'dotnet'
    2>    Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.Console.dll "F:\git\clients\hbti\Portal\hbti-web-master\HBTI.ServiceTech.AzureFunctions\bin\Debug\netcoreapp3.1\bin" "F:\git\clients\hbti\Portal\hbti-web-master\HBTI.ServiceTech.AzureFunctions\bin\Debug\netcoreapp3.1\bin\extensions.json"
    

    然后,您可能会发现它无法正常工作的实际错误:

    2>      HBTI.ServiceTech.AzureFunctions.dll
    2>        Resolving assembly: 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    2>        Assembly 'System.Runtime' loaded.
    2>        Resolving assembly: 'Microsoft.Azure.Functions.Extensions, Version=1.1.0.0, Culture=neutral, PublicKeyToken=f655f4c90a0eae19'
    2>        Assembly 'Microsoft.Azure.Functions.Extensions' loaded from 'F:\git\clients\hbti\Portal\hbti-web-master\HBTI.ServiceTech.AzureFunctions\bin\Debug\netcoreapp3.1\bin\Microsoft.Azure.Functions.Extensions.dll'.
    2>        Resolving assembly: 'Microsoft.Azure.WebJobs.Host, Version=3.0.18.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
    2>        Assembly 'Microsoft.Azure.WebJobs.Host' loaded from 'F:\git\clients\hbti\Portal\hbti-web-master\HBTI.ServiceTech.AzureFunctions\bin\Debug\netcoreapp3.1\bin\Microsoft.Azure.WebJobs.Host.dll'.
    2>        Resolving assembly: 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
    2>        Resolving assembly: 'Microsoft.AspNetCore.Mvc.Core, Culture=neutral, PublicKeyToken=null'
    2>        Cannot load 'Microsoft.AspNetCore.Mvc.Core'. Aborting assembly resolution.
    2>        Unable to find fallback for assembly 'Microsoft.AspNetCore.Mvc.Core'. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Core, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
    2>    File name: 'Microsoft.AspNetCore.Mvc.Core, Culture=neutral, PublicKeyToken=null'
    2>       at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder)
    2>       at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder)
    2>       at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, StackCrawlMark& stackMark, IntPtr pPrivHostBinder)
    2>       at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, StackCrawlMark& stackMark)
    2>       at System.Reflection.Assembly.Load(String assemblyString)
    2>       at ExtensionsMetadataGenerator.Console.Program.AssemblyLoader.<>c__DisplayClass1_0.<Initialize>b__0(Object sender, ResolveEventArgs args) in d:\a\1\s\tools\ExtensionsMetadataGenerator\src\ExtensionsMetadataGenerator.Console\Program.cs:line 78
    2>
    2>
    2>        Could not evaluate 'HBTI.ServiceTech.AzureFunctions.dll' for extension metadata. If this assembly contains a Functions extension, ensure that all dependent assemblies exist in 'F:\git\clients\hbti\Portal\hbti-web-master\HBTI.ServiceTech.AzureFunctions\bin\Debug\netcoreapp3.1\bin'. If this assembly does not contain any Functions extensions, this message can be ignored. Exception message: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
    

    在这种情况下,我的解决方案是简单地制作我自己的 extensions.json 并将其放入 bin 文件夹中:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-28
      • 2018-07-20
      • 2021-10-08
      • 2016-07-25
      • 2014-01-17
      • 1970-01-01
      相关资源
      最近更新 更多