GitHub自动化部署(CD) asp.net core 5.0 项目(免费空间)
2021/8/24 20:37:17
本文主要是介绍GitHub自动化部署(CD) asp.net core 5.0 项目(免费空间),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
这里我简单介绍一下使用Github自动化部署自己项目到Heroku云服务器上,Heroku竟然是一个很非常老牌的云平台服务商,竟然还没听说过,网上一查2010被Salesforce收购,网上有很多关于asp.net core 使用(Docker和CircleCI)部署的文章,都比较旧了,也比较麻烦,必须先配置Dockerfile再Build成功镜像再部署,但现在都是2021年了.net core又那么火什么项目都再讲CI/CD,没有理由不支持直接部署的,所以经过自己的尝试成功了,那就写一篇blog和大家分享一下。让我们开始吧。
Heroku 注册账号
Heroku: Cloud Application Platform
免费注册,这里我就不详细说明了,邮箱不要用国内厂商的就行
新建 Application
Click [New] button create new app
Input App name and Click [Create app]
配置 Application Deploy/Settings
Deployment method select GitHub(Connect to GitHub)
Search project name
Click [Connect]
你可以选择 [Enable Automatic Deploys] 如果不勾选 [wait for CI to pass before deploy] 默认 main分支一有Push或是Merge PR就会自动部署, [wait for CI to pass before deploy]的意思就是先运行集成测试脚本通过了在部署。
这是如果想 Click [Deploy Branch],是无法部署成功,会提示错误,原因就是.net core 需要.net framework编译
切换到[Settings], Click [Add buildpack]
输入: [https://github.com/jincod/dotnetcore-buildpack]
现在你再次Click [Deploy Branch] 部署就可以完成了
可以访问你的网站了[http://razorapp.herokuapp.com/authorization/profile]
回到我们Github项目中你就会看到你配置自动部署的application
在这个过程中还遇到一个错误
System.IO.DirectoryNotFoundException: /app/heroku_output/Files/
2021-08-24T12:12:01.321889+00:00 heroku[web.1]: Starting process with command `cd /app/heroku_output && ./SmartAdmin.WebUI` 2021-08-24T12:12:05.471825+00:00 app[web.1]: [12:12:05 WRN] No XML encryptor configured. Key {094ab54d-7f72-4c6f-90b3-ba4e1d9a0e49} may be persisted to storage in unencrypted form. 2021-08-24T12:12:05.512813+00:00 app[web.1]: [12:12:05 FTL] Application startup exception 2021-08-24T12:12:05.512814+00:00 app[web.1]: System.IO.DirectoryNotFoundException: /app/heroku_output/Files/ 2021-08-24T12:12:05.512825+00:00 app[web.1]: at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters) 2021-08-24T12:12:05.512829+00:00 app[web.1]: at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root) 2021-08-24T12:12:05.512830+00:00 app[web.1]: at SmartAdmin.WebUI.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in /tmp/build_08828386/src/SmartAdmin.WebUI/Startup.cs:line 104 2021-08-24T12:12:05.512831+00:00 app[web.1]: at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) 2021-08-24T12:12:05.512831+00:00 app[web.1]: at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 2021-08-24T12:12:05.512832+00:00 app[web.1]: at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder) 2021-08-24T12:12:05.512832+00:00 app[web.1]: at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder) 2021-08-24T12:12:05.512832+00:00 app[web.1]: at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app) 2021-08-24T12:12:05.512836+00:00 app[web.1]: at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder) 2021-08-24T12:12:05.512836+00:00 app[web.1]: at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app) 2021-08-24T12:12:05.512836+00:00 app[web.1]: at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken) 2021-08-24T12:12:05.516757+00:00 app[web.1]: Unhandled exception. System.IO.DirectoryNotFoundException: /app/heroku_output/Files/ 2021-08-24T12:12:05.516757+00:00 app[web.1]: at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters) 2021-08-24T12:12:05.516757+00:00 app[web.1]: at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root) 2021-08-24T12:12:05.516758+00:00 app[web.1]: at SmartAdmin.WebUI.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in /tmp/build_08828386/src/SmartAdmin.WebUI/Startup.cs:line 104 2021-08-24T12:12:05.516758+00:00 app[web.1]: at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) 2021-08-24T12:12:05.516758+00:00 app[web.1]: at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 2021-08-24T12:12:05.516758+00:00 app[web.1]: at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder) 2021-08-24T12:12:05.516759+00:00 app[web.1]: at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder) 2021-08-24T12:12:05.516759+00:00 app[web.1]: at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app) 2021-08-24T12:12:05.516760+00:00 app[web.1]: at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder) 2021-08-24T12:12:05.516760+00:00 app[web.1]: at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app) 2021-08-24T12:12:05.516760+00:00 app[web.1]: at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken) 2021-08-24T12:12:05.516760+00:00 app[web.1]: at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken) 2021-08-24T12:12:05.516761+00:00 app[web.1]: at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) 2021-08-24T12:12:05.516761+00:00 app[web.1]: at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) 2021-08-24T12:12:05.516761+00:00 app[web.1]: at SmartAdmin.WebUI.Program.Main(String[] args) in /tmp/build_08828386/src/SmartAdmin.WebUI/Program.cs:line 57 2021-08-24T12:12:05.516762+00:00 app[web.1]: at SmartAdmin.WebUI.Program.<Main>(String[] args)
没有找Files这个目录
对应这段代码
app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Files")), RequestPath = new PathString("/Files") });
我的解决方案是
在启动时新建这个目录
最后
Keeping Coding, Enjoy Coding.
如果觉得有帮助请点个赞,
我在推一下这个项目真的非常不错,喜欢轻量级开发的朋友和关注了解一下
neozhu/RazorPageCleanArchitecture
这篇关于GitHub自动化部署(CD) asp.net core 5.0 项目(免费空间)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2022-03-01沐雪多租宝商城源码从.NetCore3.1升级到.Net6的步骤
- 2024-12-06使用Microsoft.Extensions.AI在.NET中生成嵌入向量
- 2024-11-18微软研究:RAG系统的四个层次提升理解与回答能力
- 2024-11-15C#中怎么从PEM格式的证书中提取公钥?-icode9专业技术文章分享
- 2024-11-14云架构设计——如何用diagrams.net绘制专业的AWS架构图?
- 2024-05-08首个适配Visual Studio平台的国产智能编程助手CodeGeeX正式上线!C#程序员必备效率神器!
- 2024-03-30C#设计模式之十六迭代器模式(Iterator Pattern)【行为型】
- 2024-03-29c# datetime tryparse
- 2024-02-21list find index c#
- 2024-01-24convert toint32 c#