[英].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.