【问题标题】:Why does GenerateFunctions fail looking for System.Runtime, Version=4.2.1.0 and throws a FileNotFoundException)?为什么 GenerateFunctions 找不到 System.Runtime, Version=4.2.1.0 并抛出 FileNotFoundException)?
【发布时间】:2019-07-31 13:09:59
【问题描述】:

我有一个 Azure Function v2 创建为 DotNet Core 库 (2.1),使用最新的 1.0.26 Microsoft.Net.Sdk.Functions NuGet 包。

我无法构建 Azure Functions,因为 GenerateFunctions 任务正在寻找 System.Runtime 的 4.2.1.0 版本。但是,没有该特定版本的 NuGet 包。

问题

谁在寻找 System.Runtime 4.2.1.0,我该如何解决?

这是失败的构建的诊断日志部分:

2>Target "_GenerateFunctionsPostBuild" in file "C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets":
2>  Using "Move" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
2>  Task "Move"
2>    Task Parameter:SourceFiles=C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\NoSuchCompany.Demo.Service.AzureFunctions.pdb
2>    Task Parameter:DestinationFiles=C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\bin\NoSuchCompany.Demo.Service.AzureFunctions.pdb
2>    Task Parameter:OverwriteReadOnlyFiles=True
2>    Moving file from "C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\NoSuchCompany.Demo.Service.AzureFunctions.pdb" to "C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\bin\NoSuchCompany.Demo.Service.AzureFunctions.pdb".
2>  Done executing task "Move".
2>  Using "GenerateFunctions" task from assembly "C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\..\..\tools\net46\\Microsoft.NET.Sdk.Functions.MSBuild.dll".
2>  Task "GenerateFunctions"
2>    Task Parameter:TargetPath=C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\bin\NoSuchCompany.Demo.Service.AzureFunctions.dll
2>    Task Parameter:OutputPath=C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\
2>    Function generator path: 'C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\tools\net46\Microsoft.NET.Sdk.Functions.Generator.exe'
2>    "C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\bin\NoSuchCompany.Demo.Service.AzureFunctions.dll " "C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\ "
2>    C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): error : System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
2>    C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): error : File name: 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
2>    C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): error :    at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
2>    C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): error :    at System.Reflection.RuntimeAssembly.GetExportedTypes()
2>    C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): error :    at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
2>    C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): error :    at MakeFunctionJson.FunctionJsonConverter.TryRun()
2>    C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): error : 
2>    C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): error : WRN: Assembly binding logging is turned OFF.
2>    C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): error : To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
2>    C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): error : Note: There is some performance penalty associated with assembly bind failure logging.
2>    C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): error : To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
2>    C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): error : 
2>    C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): error : Error generating functions metadata
2>    C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): error :
2>    C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): error : Metadata generation failed.
2>  Done executing task "GenerateFunctions" -- FAILED.
2>Done building target "_GenerateFunctionsPostBuild" in project "Demo.Service.AzureFunctions.csproj" -- FAILED.

更新 1

如果我运行以下命令,我会得到完全相同的错误:

C:\Users\Chris.nuget\packages\microsoft.net.sdk.functions\1.0.26\tools\net46>Microsoft.NET.Sdk.Functions.Generator.exe "C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\bin\NoSuchCompany.Demo.Service.AzureFunctions.dll " "C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\ "

我得到以下输出:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
   at System.Reflection.RuntimeAssembly.GetExportedTypes()
   at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
   at MakeFunctionJson.FunctionJsonConverter.TryRun()

Error generating functions metadata

更新 2

我想知道为什么构建使用Microsoft.NET.Sdk.Functions.Generator 的网络框架版本,因为有一个netcore 版本。出于好奇,我用netcore版本试了一下:

C:\Users\Chris.nuget\packages\microsoft.net.sdk.functions\1.0.26\tools\netcoreapp2.1>dotnet Microsoft.NET.Sdk.Functions.Generator.dll "C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\bin\NoSuchCompany.Demo.Service.AzureFunctions.dll" "C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1"

没有错误。我猜.net 4.6 版本有问题。你呢?

【问题讨论】:

    标签: c# azure msbuild azure-functions


    【解决方案1】:

    我在Microsoft.NET.Sdk.Functions.Build.targets 文件中找到了使用.Net Core 运行时而不是.Net Framework 的条件:

     <PropertyGroup>
          <UseNETCoreGenerator Condition="$(UseNETCoreGenerator)=='' AND ($(AzureFunctionsVersion) == 'v2' OR $(AzureFunctionsVersion) == 'v2-prerelease' )">true</UseNETCoreGenerator>
    </PropertyGroup>
    

    然后我查看了我的 Azure Functions 的 .csproj 文件,发现 AzureFunctionsVersion 标记拼写错误,并且在 Function: 后缺少 s

    <PropertyGroup>
      <TargetFramework>netcoreapp2.1</TargetFramework>
      <AzureFunctionsVersion>v2</AzureFunctionsVersion>
      <AssemblyName>NoSuchCompany.Demo.Service.AzureFunctions</AssemblyName>
      <RootNamespace>NoSuchCompany.Demo.Service</RootNamespace>
      <OutputType>Library</OutputType>
    </PropertyGroup>
    

    修正后,我得到了预期的成功构建输出,尤其是指示使用 .Net 核心生成器的部分:

    Target "_GenerateFunctionsPostBuild" in file "C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets":
    
    2>  Set Property: UseNETCoreGenerator=true
    
    2>  Using "Move" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
    2>  Task "Move"
    2>    Task Parameter:SourceFiles=C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\NoSuchCompany.Demo.Service.AzureFunctions.pdb
    2>    Task Parameter:DestinationFiles=C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\bin\NoSuchCompany.Demo.Service.AzureFunctions.pdb
    2>    Task Parameter:OverwriteReadOnlyFiles=True
    2>    Moving file from "C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\NoSuchCompany.Demo.Service.AzureFunctions.pdb" to "C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\bin\NoSuchCompany.Demo.Service.AzureFunctions.pdb".
    2>  Done executing task "Move".
    2>  Using "GenerateFunctions" task from assembly "C:\Users\Chris\.nuget\packages\microsoft.net.sdk.functions\1.0.26\build\netstandard1.0\..\..\tools\net46\\Microsoft.NET.Sdk.Functions.MSBuild.dll".
    2>  Task "GenerateFunctions"
    2>    Task Parameter:TargetPath=C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\bin\NoSuchCompany.Demo.Service.AzureFunctions.dll
    2>    Task Parameter:OutputPath=C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\
    2>    Task Parameter:UseNETCoreGenerator=True
    2>    Function generator path: 'dotnet'
    2>    Microsoft.NET.Sdk.Functions.Generator.dll "C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\bin\NoSuchCompany.Demo.Service.AzureFunctions.dll " "C:\NoSuchCompany\Service\src\bin\Debug\netcoreapp2.1\ "
    2>  Done executing task "GenerateFunctions".
    2>Done building target "_GenerateFunctionsPostBuild" in project "Demo.Service.AzureFunctions.csproj".
    

    【讨论】:

    • 感谢您为我们指明了正确的方向。我们的情况略有不同,因为 AzureFunctionsVersion 元素为空:&lt;AzureFunctionsVersion&gt;&lt;/AzureFunctionsVersion&gt; 我们只需将其更新如下:&lt;AzureFunctionsVersion&gt;v2&lt;/AzureFunctionsVersion&gt;
    • 感谢发帖。我遇到了同样的问题,这对我来说就像魔术一样;)
    • 我已将 host.json 更改为 version 键为 2.0 并将目标框架更改为 .NET Core 2.2 但 AzureFunctionsVersion xml 标记中的值是 v3
    猜你喜欢
    • 1970-01-01
    • 2019-04-23
    • 2013-12-08
    • 1970-01-01
    • 1970-01-01
    • 2016-03-04
    • 1970-01-01
    • 2018-08-18
    • 2015-11-09
    相关资源
    最近更新 更多