国产中标麒麟Linux部署dotnet core 环境并运行项目 (三) 部署运行WEB API项目

部署dotnet Core Web API

上一步的文章,是我们公司最核心的一个ORM组件,在中标麒麟系统完成了一个插入数据的任务,这一步是将正式的从dot net framework 迁移到 dotnet core 的项目,部署运行在中标麒麟系统中。

项目预览

现有从dotnet framework 迁移过来的一个 dotnet core web api 项目,准备部署中标麒麟系统上测试运行,下面是项目截图:

image

运行 & 解决

将文件上传到服务器上,然后执行命令运行:

[root@gumis02 API]# dotnet Beyondbit.One.BUA.API.dll Error: An assembly specified in the application dependencies manifest (Beyondbit.One.BUA.API.deps.json) was not found: package: \'Microsoft.ApplicationInsights.AspNetCore\', version: \'2.1.1\' path: \'lib/netstandard1.6/Microsoft.ApplicationInsights.AspNetCore.dll\' This assembly was expected to be in the local runtime store as the application was published using the following target manifest files: aspnetcore-store-2.0.0-linux-x64.xml;aspnetcore-store-2.0.0-osx-x64.xml;aspnetcore-store-2.0.0-win7-x64.xml;aspnetcore-store-2.0.0-win7-x86.xml [root@gumis02 API]#

果不既然错误可能会迟到,但是绝不缺席,显示的错误是在开发过程中应用的nuget dll 找不到。这个问题是个小问题,已经有同学写了文章,Fix *.deps.json was not found,文章提到的解决办法:

增加如下一行到 csjproj文件中即可:false
最后csjproj文件看上去像这个样子:

<PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest> </PropertyGroup>

重新发布项目,然后运行上面的问题已经解决,出现其他的问题:

[root@gumis02 API]# dotnet Beyondbit.One.BUA.API.dll warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35] No XML encryptor configured. Key {0372b52e-5124-4655-871b-906a0467a642} may be persisted to storage in unencrypted form. Application startup exception: System.InvalidOperationException: No service for type \'Microsoft.AspNetCore.Http.IHttpContextAccessor\' has been registered. at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Beyondbit.Framework.StaticHttpContextExtensions.UseStaticHttpContext(IApplicationBuilder app, HttpContextOptions options) at Beyondbit.One.BUA.API.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in E:\\u5de5\u4f5c\u533a\03 \u4e92\u8054\u7f51\03 \u7edf\u4e00\u7cfb\u5217\01_TFS\03\u7248\u672c\u7ba1\u7406\Beyondbit E-GOV Base System Suite\\u7edf\u4e00\u6388\u6743\CoreV1\Beyondbit.One.BUA.API\Startup.cs:line 49 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app) at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() crit: Microsoft.AspNetCore.Hosting.Internal.WebHost[6] Application startup exception System.InvalidOperationException: No service for type \'Microsoft.AspNetCore.Http.IHttpContextAccessor\' has been registered. at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Beyondbit.Framework.StaticHttpContextExtensions.UseStaticHttpContext(IApplicationBuilder app, HttpContextOptions options) at Beyondbit.One.BUA.API.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in E:\\u5de5\u4f5c\u533a\03 \u4e92\u8054\u7f51\03 \u7edf\u4e00\u7cfb\u5217\01_TFS\03\u7248\u672c\u7ba1\u7406\Beyondbit E-GOV Base System Suite\\u7edf\u4e00\u6388\u6743\CoreV1\Beyondbit.One.BUA.API\Startup.cs:line 49 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app) at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() Unhandled Exception: System.InvalidOperationException: No service for type \'Microsoft.AspNetCore.Http.IHttpContextAccessor\' has been registered. at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Beyondbit.Framework.StaticHttpContextExtensions.UseStaticHttpContext(IApplicationBuilder app, HttpContextOptions options) at Beyondbit.One.BUA.API.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in E:\\u5de5\u4f5c\u533a\03 \u4e92\u8054\u7f51\03 \u7edf\u4e00\u7cfb\u5217\01_TFS\03\u7248\u672c\u7ba1\u7406\Beyondbit E-GOV Base System Suite\\u7edf\u4e00\u6388\u6743\CoreV1\Beyondbit.One.BUA.API\Startup.cs:line 49 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app) at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build() at Beyondbit.One.BUA.API.Program.Main(String[] args) in E:\\u5de5\u4f5c\u533a\03 \u4e92\u8054\u7f51\03 \u7edf\u4e00\u7cfb\u5217\01_TFS\03\u7248\u672c\u7ba1\u7406\Beyondbit E-GOV Base System Suite\\u7edf\u4e00\u6388\u6743\CoreV1\Beyondbit.One.BUA.API\Program.cs:line 17 \u5df2\u653e\u5f03 (core dumped) [root@gumis02 API]#

错误提示确实依赖:
在Starpup.cs 加入一段话:

services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgwwwy.html