ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,157 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
in my project i have to build a core and modules for project i found OrchardCore but the problem is : i want to build a platform that upload the module (package with .nupkg type) and install into my released project on the server now i have a simple project : enter image description here => my solution Explorer
my core 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), 0, (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();
}
}
}
my core 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>();
});
}
}
my module 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>();
});
}
}
my module 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)
{
}
}
}
now i confused how to install my module from .nupkg file to the project when the core is on the server and all of the application is ONLINE