为什么 GenerateFunctions 无法查找 System.Runtime, Version=4.2.1.0 并抛出 FileNotFoundException)?

Kzr*_*tof 1 c# msbuild azure azure-functions

我使用最新的 1.0.26 Microsoft.Net.Sdk.FunctionsNuGet 包将 Azure Function v2 创建为 DotNet Core 库 (2.1) 。

我无法构建 Azure Functions,因为该GenerateFunctions任务正在寻找System.Runtime. 但是,没有该特定版本的 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.
Run Code Online (Sandbox Code Playgroud)

更新 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
Run Code Online (Sandbox Code Playgroud)

更新 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 版本有问题。你呢?

Kzr*_*tof 5

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

 <PropertyGroup>
      <UseNETCoreGenerator Condition="$(UseNETCoreGenerator)=='' AND ($(AzureFunctionsVersion) == 'v2' OR $(AzureFunctionsVersion) == 'v2-prerelease' )">true</UseNETCoreGenerator>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

然后我.csproj查看了我的 Azure Functions 文件,发现AzureFunctionsVersion标签拼写错误并且缺少一个safter 函数:

<PropertyGroup>
  <TargetFramework>netcoreapp2.1</TargetFramework>
  <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  <AssemblyName>NoSuchCompany.Demo.Service.AzureFunctions</AssemblyName>
  <RootNamespace>NoSuchCompany.Demo.Service</RootNamespace>
  <OutputType>Library</OutputType>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

一旦得到纠正,我就得到了预期的成功构建输出,尤其是指示使用 .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".
Run Code Online (Sandbox Code Playgroud)