Electron.NET
Electron.NET copied to clipboard
Visual studio 2022 net core 6 In Electron.NET The code is not the same
Please, leave a sample of the new code in Visual Studio 2022 net core 6 in this new github. Every time I searched Google, unfortunately, all the tutorials and all the code defined a sample of the Visual Studio 2019 net core 5 version.
Please modify the new code for the next version.
just use the sample api code to get started because they havent updated it. if you get the sample api demo working then you can see the documentation but im pretty sure its actually the same on the website.
Please, leave a sample of the new code in Visual Studio 2022 net core 6 in this new github. Every time I searched Google, unfortunately, all the tutorials and all the code defined a sample of the Visual Studio 2019 net core 5 version.
Please modify the new code for the next version.
I hope someone adds some examples for .NET6 soon.
I finally got this running with VS 2022, VS Code on .NET6. After installing electronNET into my ASP.NET Core app, I had to add a Startup.cs and use namespaces and class names like a civilized person lol.
Program.cs
using ElectronNET.API;
namespace TheBestNamespace
{
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.UseElectron(args);
webBuilder.UseEnvironment("Development");
webBuilder.UseStartup<Startup>();
});
}
}
Startup.cs
using ElectronNET.API;
using ElectronNET.API.Entities;
namespace TheBestNamespace
{
public class Startup
{
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.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
//services.AddSingleton(sg => { var log = sg.GetService<ILogger<Startup>>()});
services.AddRazorPages();
//services.AddServerSideBlazor();
//services.AddSingleton<MyService>(); // Other singletons
}
// 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(); // disabled in project settings webserver too.
app.UseStaticFiles();
app.UseRouting();
// For blazor
//app.UseEndpoints(endpoints =>
//{
// endpoints.MapBlazorHub();
// endpoints.MapFallbackToPage("/_Host");
//});
// For regular
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
if (HybridSupport.IsElectronActive)
{
ElectronCreateWindow();
}
}
public async void ElectronCreateWindow()
{
var browserWindowOptions = new BrowserWindowOptions
{
Width = 1024,
Height = 768,
Show = false, // wait to open it
WebPreferences = new WebPreferences
{
WebSecurity = false
}
};
var browserWindow = await Electron.WindowManager.CreateWindowAsync(browserWindowOptions);
await browserWindow.WebContents.Session.ClearCacheAsync();
// Handler to show when it is ready
browserWindow.OnReadyToShow += () =>
{
browserWindow.Show();
};
// Close Handler
browserWindow.OnClose += () => Environment.Exit(0);
}
}
}
@ackerman76
Great . Thankyou. So please update Git "Net 6" And "VS2022" at the gate .
@ackerman76 what version of electronNET did you use?
@ackerman76 what version of electronNET did you use?
13.5.1
The following code for .NET 6 worked for me. Is a bit closer to the default setup/style.
using ElectronNET.API;
namespace SomeProgram
{
public class Program
{
public static void Main(string[] args)
{
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// Configure webhost
builder.WebHost.UseElectron(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
WebApplication app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/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.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
if (HybridSupport.IsElectronActive)
CreateElectronWindow();
app.Run();
}
static async void CreateElectronWindow()
{
BrowserWindow window = await Electron.WindowManager.CreateWindowAsync();
window.OnClosed += () => Electron.App.Quit();
}
}
}
🎉🚀 New Electron.NET version 23.6.1 released 🚀🎉
With native Electron 23 and .NET 6 support. Your problem should be fixed here. If you continue to have the problem, please let us know. Please note the correct updating of your API & CLI. Info in the README. Have fun!