Azure Functions Swashbuckle:在重建期间无法解析程序集“Microsoft.AspNetCore.Mvc.Core”

Posted

技术标签:

【中文标题】Azure Functions Swashbuckle:在重建期间无法解析程序集“Microsoft.AspNetCore.Mvc.Core”【英文标题】:Azure Functions Swashbuckle: Failed to resolve assembly 'Microsoft.AspNetCore.Mvc.Core' during rebuild 【发布时间】:2021-11-28 12:19:39 【问题描述】:

我想将 OpenAPI 规范添加到我的 Azure Functions 应用。为此,我想使用AzureExtensions.Swashbuckle,因为它可以自动生成规范并通过 swagger-ui 显示它。

当我第一次通过nuget 安装软件包时,一切正常。规范是自动生成的,我可以通过swagger-ui查看。

一旦我重建我的项目/解决方案,它就不再构建。构建过程中提示如下错误信息:

3>C:\Users\Agent1\.nuget\packages\microsoft.net.sdk.functions\3.0.13\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): Error  : Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name)
   at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
   at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
   at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type)
   at Mono.Cecil.TypeReference.Resolve()
   at MakeFunctionJson.AttributeExtensions.IsWebJobsAttribute(CustomAttribute attribute)
   at MakeFunctionJson.ParameterInfoExtensions.<>c.<ToFunctionJsonBindings>b__1_0(CustomAttribute a)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at MakeFunctionJson.ParameterInfoExtensions.ToFunctionJsonBindings(ParameterDefinition parameterInfo)
   at MakeFunctionJson.MethodInfoExtensions.<>c.<ToFunctionJson>b__6_1(ParameterDefinition p)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.ToArray()
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at MakeFunctionJson.MethodInfoExtensions.ToFunctionJson(MethodDefinition method, String assemblyPath)
   at MakeFunctionJson.FunctionJsonConverter.GenerateFunctions(IEnumerable`1 types)+MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
   at MakeFunctionJson.FunctionJsonConverter.TryRun()
Error generating functions metadata

我正在使用带有 .NET Core 3.1 的 AzureFunctions V3。

这是我的 .csproj 文件:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
    <OutputPath>../../dist/apps/api</OutputPath>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AzureExtensions.Swashbuckle" Version="3.3.2" />
    <PackageReference Include="CSharpFunctionalExtensions" Version="2.18.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.0.0-beta.5" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.17">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.17" />
    <PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.12.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" />
    <PackageReference Include="Scriban" Version="4.0.1" />
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.8.1" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.8.1" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.8.1" />
    <PackageReference Include="System.ServiceModel.Security" Version="4.8.1" />
  </ItemGroup>

  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

我已经删除了我的本地 .nuget 目录,清理了 nuget 缓存并更新了其他包,但没有运气。

【问题讨论】:

【参考方案1】:

如果您将[FromQuery] 或任何其他属性添加到您的天蓝色函数“控制器签名”,它可能会发生。 您可以尝试删除[FromQuery] 属性。

你可以参考这个正在进行的 github issue 关于同样的问题。

【讨论】:

啊,我在其中一个函数中设置了 [FromBody] 属性。我只搜索了[FromQuery]。现在一切正常。谢谢。

以上是关于Azure Functions Swashbuckle:在重建期间无法解析程序集“Microsoft.AspNetCore.Mvc.Core”的主要内容,如果未能解决你的问题,请参考以下文章

AZURE_FUNCTIONS_ENVIRONMENT 与 ASPNETCORE_ENVIRONMENT

Azure Functions 与 Azure 流分析

使用“apollo-server-azure-functions”的 Apollo 订阅

在 Java 中使用 Visual Studio Code 的 Azure Functions 项目

Azure Functions 未在本地创建 Azure 表列

Azure Functions - 根据事件类型阻止处理 Azure 服务总线消息