果园核心问题以编程方式添加模块

问题描述

在我的项目中,我必须为我找到的项目构建一个核心和模块 OrchardCore 但问题是: 我想构建一个上传模块(带有 .nupkg 类型的包)并安装到我在服务器上发布的项目中的平台 现在我有一个简单的项目: enter image description here => 我的解决方案资源管理器 我的核心startup.cs:

    using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.Loader;
using System.Threading.Tasks;

namespace modularv001
{
    public class Startup
    {
        private IList<AssemblyHanlder> components = new List<AssemblyHanlder>();
        private void GetallModules()
        {
            var rootPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            string InstallPath = Path.Combine(rootPath,"InstalledModules");
            rootPath = Path.Combine(rootPath,"container");
            foreach (string file in Directory.EnumerateFiles(rootPath,"*.nupkg",SearchOption.AllDirectories))
            {
                using (ZipArchive nuget = ZipFile.Open(file,ZipArchiveMode.Read))
                {
                    foreach (ZipArchiveEntry entry in nuget.Entries)
                    {
                        if (entry.Name.Contains(".dll"))
                        {
                            string createPathSource = InstallPath + "\\" + entry.Name;

                            using (BinaryReader reader = new BinaryReader(entry.open()))
                            {
                                // Step 1
                                using (FileStream fsNew = new FileStream(createPathSource,FileMode.Create,FileAccess.Write))
                                {
                                    fsNew.Write(reader.ReadBytes((int)entry.Length),(int)entry.Length);
                                }

                                // Step 2
                                using (FileStream readStream = File.Open(createPathSource,FileMode.Open))
                                {
                                    var assempbly = AssemblyLoadContext.Default.LoadFromStream(readStream);
                                    if (entry.Name.Contains(".Views.dll"))
                                    {
                                        components.Add(new AssemblyHanlder()
                                        {
                                            components = assempbly,isView = true
                                        });
                                    }
                                    else
                                    {
                                        components.Add(new AssemblyHanlder()
                                        {
                                            components = assempbly,isView = false
                                        });
                                    }

                                }
                            }
                        }





                    }
                }
            }
        }
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Addorchardcore().AddMvc();
            GetallModules();
            /*=======================================================
             
             
             load module in  private IList<AssemblyHanlder> components = new List<AssemblyHanlder>();
                 internal class AssemblyHanlder
                {
                    public Assembly components { get; set; }
                    public bool isView { get; set; }
                 }
             
             ==========================================================*/

        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios,see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();
            app.Useorchardcore();
        }
    }
}

我的核心 Program.cs :

  using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace modularv001
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }
}

 

我的模块 program.cs :

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Module1
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }
}

我的模块startup.cs:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Module1
{
    public class Startup
    {
        public void Configure(IEndpointRouteBuilder endpoints)
        {

        }
    }
}

现在我很困惑,当核心在服务器上并且所有应用程序都在线时,如何将我的模块从 .nupkg 文件安装到项目中

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...