简体   繁体   English

.NET Core 3.1 web API 在本地构建良好,但通过 Z3A580F1420psO3psO3973F13ZB0 Dev 部署时出错

[英].NET Core 3.1 web API builds fine locally, but gets errors when deploying via Azure DevOps

I had a similar problem a couple weeks ago:几周前我遇到了类似的问题:

I'm getting the error "Microsoft.AspNetCore.Hosting.Abstractions, Version=3.1.0.0" in .NET Core 3.1 app 我在 .NET Core 3.1 应用程序中收到错误“Microsoft.AspNetCore.Hosting.Abstractions, Version=3.1.0.0”

I can run it from Visual Studio 2019 locally with no issues, but whenever I try to run it after deploying via Azure DevOps, I get this error:我可以在本地从 Visual Studio 2019 运行它而没有问题,但是每当我在通过 Azure DevOps 部署后尝试运行它时,我都会收到此错误:

Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
File name: 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
   at System.Reflection.RuntimeMethodInfo.get_ReturnType()
   at Microsoft.AspNetCore.Hosting.StartupLoader.FindMethod(Type startupType, String methodName, String environmentName, Type returnType, Boolean required)
   at Microsoft.AspNetCore.Hosting.StartupLoader.HasConfigureServicesIServiceProviderDelegate(Type startupType, String environmentName)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at KindRegards.Web.Api.Program.Main(String[] args) in /home/vsts/work/1/s/src/Api/Program.cs:line 10

I don't fully understand how all of this ties together, so I tried adding:我不完全理解所有这些是如何联系在一起的,所以我尝试添加:

    <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />

but that didn't work.但这没有用。 I have other "Microsoft.Extension" packages that are using version 3.1.8, so I tried matching those by adding:我有其他使用 3.1.8 版的“Microsoft.Extension”包,所以我尝试通过添加来匹配它们:

    <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.8" />

But then I couldn't run it locally, and I get this error:但是后来我无法在本地运行它,并且出现此错误:

NU1605  Detected package downgrade: Microsoft.Extensions.DependencyInjection.Abstractions from 5.0.0 to 3.1.8. Reference the package directly from the project to select a different version. 
 KindRegards.Web.Api -> KindRegards.Plugins.PaymentProcessors.GreenMoney -> Microsoft.Extensions.Http 5.0.0 -> Microsoft.Extensions.DependencyInjection.Abstractions (>= 5.0.0) 
 KindRegards.Web.Api -> Microsoft.Extensions.DependencyInjection.Abstractions (>= 3.1.8)    Web.Api Z:\Projects\KindRegards\src\Api\Web.Api.csproj  1   

I'm not sure how to even begin digging into this.我什至不知道如何开始深入研究。 Any help would be appreciated.任何帮助,将不胜感激。

It happened with me before while using Azure DevOps and the solution was to check what is Azure DevOps using and I matched the project with it, I mean your target should be the version that Azure DevOps agent is using.我之前在使用Azure DevOps时发生过这种情况,解决方案是检查Azure DevOps使用的是什么,我将项目与之匹配,我的意思是您的目标应该是Azure DevOps代理使用的版本。

I do not remember exactly, but most likely I downgraded my app version to match the Azure DevOps.我不记得确切,但很可能我降级了我的应用程序版本以匹配 Azure DevOps。

This happens generally when your Visual Studio automatic updates are enabled so your.Net Core nugets become more up to date than the ones used in Azure DevOps这通常在启用 Visual Studio 自动更新时发生,因此您的 .Net Core nuget 比 Azure DevOps 中使用的更新

It appears that you created your project targeting.Net 5, which is great.看来您创建了针对.Net 5 的项目,这很棒。 Restore your project the way you had it originally and add another step to your pipeline where you install.Net 5.0.100.以最初的方式恢复您的项目,并在安装.Net 5.0.100 的管道中添加另一个步骤。 I think the link below may help.我认为下面的链接可能会有所帮助。

Azure Pipeline Failing in dotnet build, need to upgrade to latest .net core version Azure 管道在 dotnet 构建中失败,需要升级到最新的 .net 核心版本

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Azure Devops部署时的Asp Core Web App,404,通过Visual Studio发布时为200 - Asp Core Web App, 404 when deploying with Azure Devops, 200 when publishing via Visual studio 为什么我可以在本地运行来自 a.Net Core 3.1 web 应用程序的外部 HTTP 调用,但在发布到 Azure 网站时不能运行? - Why can I run external HTTP calls from a .Net Core 3.1 web app locally, but not when published to Azure Websites? ASP.NET Core 2.0 Web 应用程序在将项目部署到 Azure Web 服务时失败并出现 SQLite 错误,但在本地环境中运行良好 - ASP.NET Core 2.0 Web Application fails with a SQLite error when deploying the project to Azure Web Service but runs fine in local environment Azure App Servce 的 .Net Core 3.1 Web API 延迟问题 - .Net Core 3.1 Web API latency issue with Azure App Servce ASP.NET Core 3.1 API 参考 a.Net Standard class 库 - 在 Azure DevOps 中构建失败 - ASP.NET Core 3.1 API referring to a .Net Standard class library - build failed in Azure DevOps 当本地调用 Web API 时,通过 Web API 连接到 Access 数据库工作正常,但远程调用异常 - Connection to Access database via Web API works fine when Web API is called locally, but exception on remote calls .net 核心 3.1 Azure devops 管道在 nuget 恢复时失败 - .net core 3.1 Azure devops Pipeline failed on nuget restore 将 ASP.NET CORE 3.1 MVC 应用程序部署到 azure 时出现问题 - Problem deploying ASP.NET CORE 3.1 MVC app to azure .NET Core API 在 Azure 上部署后无法正常工作 - .NET Core API not working after deploying on Azure 托管在 Azure Web 应用程序上的 API 返回没有名称 .Net core 3.1 的 JSON 数组 - API hosted on Azure web app returns JSON Array with out the Name .Net core 3.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM