为什么GenerateFunctions在查找System.Runtime,Version = 4.2.1.0时失败,并抛出FileNotFoundException)?

时间:2019-03-09 19:38:20

标签: c# azure msbuild azure-functions

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

我无法构建Azure功能,因为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版本有问题。你呢?

1 个答案:

答案 0 :(得分: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".