gpt4 book ai didi

c# - 为什么GenerateFunctions 查找System.Runtime、Version=4.2.1.0 失败并抛出FileNotFoundException)?

转载 作者:行者123 更新时间:2023-12-02 07:40:02 25 4
gpt4 key购买 nike

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

我无法构建 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 版本有问题。你是吗?

最佳答案

我在 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 标签拼写错误并且缺少 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 core 生成器的部分:

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".

关于c# - 为什么GenerateFunctions 查找System.Runtime、Version=4.2.1.0 失败并抛出FileNotFoundException)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55081214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com