Zurück zum Ranking

ElectronNET/Electron.NET

C#gitter.im/ElectronNET/community

:electron: Build cross platform desktop apps with ASP.NET Core (Razor Pages, MVC, Blazor).

electrondotnetdotnet-coredotnet-standardasp-net-coreasp-net-core-mvcaspnetelectron-netblazorblazor-serverblazor-webassemblycross-platform
Sterne-Wachstum
Sterne
7.6k
Forks
746
Wochenwachstum
Issues
21
2k4k6k
Okt. 2017Sept. 2020Aug. 2023Juli 2026
README

Electron.NET Logo

donate Gitter Build status

Electron.NET Core is here!

A Complete Transformation

ElectronNET.Core represents a fundamental modernization of Electron.NET, addressing years of accumulated pain points while preserving full API compatibility. This isn't just an update — it's a complete rethinking of how .NET developers build and debug cross-platform desktop applications with Electron.

Read more: What's New in ElectronNET.Core

Build cross platform desktop applications with .NET 6/8/10 - from console apps to ASP.NET Core (Razor Pages, MVC) to Blazor.

Wait - how does that work exactly?

Well... there are lots of different approaches how to get a X-plat desktop app running. Electron.NET provides a range of ways to build .NET-based solutions using Electron at the side of presentation.

While the classic Electron.NET setup (using an ASP.NET host run by the Electron side) is still the primary way, there's more flexibility now. Both .NET and Electron are now able to launch the other for better lifetime management, and when you don't need a local web server (like when running content from files or remote servers), you can drop the ASP.NET stack altogether and go with a lightweight console app instead.

📦 NuGet

  • ElectronNET.Core: NuGet
  • ElectronNET.Core.API: NuGet
  • ElectronNET.Core.AspNet: NuGet

🛠 Requirements to Run

You should have installed:

👩‍🏫 Usage with ASP.NET

  • Create a new ASP.NET Core project
  • Install the following two NuGet packages:
dotnet add package ElectronNET.Core

dotnet add package ElectronNET.Core.AspNet

Classic ASP.NET Core

Enable Electron.NET on Startup

To do so, use the UseElectron extension method on a WebApplicationBuilder, an IWebHostBuilder or any descendants.

[!NOTE]
New in Electron.NET Core is that you provide a callback method as an argument to UseElectron(), which ensures that you get to know the right moment to set up your application UI.

Program.cs

using ElectronNET.API;
using ElectronNET.API.Entities;

public static void Main(string[] args)
{
    WebHost.CreateDefaultBuilder(args)
        .UseElectron(args, ElectronAppReady)
        .UseStartup<Startup>()
        .Build()
        .Run();
}

public static async Task ElectronAppReady()
{
    var browserWindow = await Electron.WindowManager.CreateWindowAsync(
        new BrowserWindowOptions { Show = false });

    browserWindow.OnReadyToShow += () => browserWindow.Show();
}

Minimal API Example

For a minimal API you can use:

using ElectronNET;
using ElectronNET.API;
using ElectronNET.API.Entities;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorPages();
builder.Services.AddElectron(); // <- might be useful to set up DI

builder.UseElectron(args, async () =>
{
    var browserWindow = await Electron.WindowManager.CreateWindowAsync(
        new BrowserWindowOptions { Show = false, AutoHideMenuBar = true });

    browserWindow.OnReadyToShow += () => browserWindow.Show();
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
}

app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.Run();

Blazor

For a project with Blazor you can use:

using ElectronNET.API;
using ElectronNET.API.Entities;

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddRazorComponents()
    .AddInteractiveWebAssemblyComponents();

builder.Services.AddElectron(); // <-- might be useful to set up DI

builder.UseElectron(args, async () =>
{
    var options = new BrowserWindowOptions {
        Show = false,
        IsRunningBlazor = true, // <-- crucial
    };
    if (OperatingSystem.IsWindows() || OperatingSystem.IsLinux())
        options.AutoHideMenuBar = true;
    var browserWindow = await Electron.WindowManager.CreateWindowAsync(options);
    browserWindow.OnReadyToShow += () => browserWindow.Show();
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseWebAssemblyDebugging();
}
else
{
    app.UseExceptionHandler("/Error", createScopeForErrors: true);
}

app.UseStaticFiles();
app.UseAntiforgery();

app.MapRazorComponents<BlazorApp.Components.App>()
    .AddInteractiveWebAssemblyRenderMode();

app.Run();

The IsRunningBlazor option makes sure to set up the renderer in a way that Blazor can just run without any interference. This includes things such as HMR for development.

🚀 Starting and Debugging the Application

Just press F5 in Visual Studio or use dotnet for debugging.

📔 Usage of the Electron API

Complete documentation is available on the Wiki.

In this YouTube video, we show you how you can create a new project, use the Electron.NET API, debug a application and build an executable desktop app for Windows: Electron.NET - Getting Started

[!NOTE]
The video hasn't been updated for the changes in ElectronNET.Core, so it is partially outdated.

👨‍💻 Authors

  • Gregor Biswanger - (Microsoft MVP, Intel Black Belt and Intel Software Innovator) is a freelance lecturer, consultant, trainer, author and speaker. He is a consultant for large and medium-sized companies, organizations and agencies for software architecture, web- and cross-platform development. You can find Gregor often on the road attending or speaking at international conferences. - Cross-Platform-Blog - Twitter @BFreakout
  • Dr. Florian Rappl - Software Developer - from Munich, Germany. Microsoft MVP & Web Geek. - The Art of Micro Frontends - Homepage - Twitter @florianrappl
  • softworkz - Full Range Developer - likes to start where others gave up. MS MVP alumni and Munich citizen as well.
  • Robert Muehsig - Software Developer - from Dresden, Germany, now living & working in Switzerland. Microsoft MVP & Web Geek. - codeinside Blog - Twitter @robert0muehsig

See also the list of contributors who participated in this project.

🙋‍♀️🙋‍♂ Contributing

Feel free to submit a pull request if you find any bugs (to see a list of active issues, visit the Issues section. Please make sure all commits are properly documented.

We do this open source work in our free time. If you'd like us to invest more time on it, please donate. Donation can be used to increase some issue priority. Thank you!

donate

Alternatively, consider using a GitHub sponsorship for the core maintainers:

Any support appreciated! 🍻

🎉 License

MIT-licensed. See LICENSE for details.

Enjoy!

Ähnliche Repositories
microsoft/vscode

Visual Studio Code

TypeScriptnpmMIT Licenseeditorelectron
code.visualstudio.com
187.8k41.3k
electron/electron

:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS

C++MIT Licenseelectronjavascript
electronjs.org
122.1k17.3k
microsoft/playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

TypeScriptnpmApache License 2.0playwrighttesting
playwright.dev
93.2k6.1k
toeverything/AFFiNE

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

TypeScriptnpmOthereditorcrdt
affine.pro
70.6k5.1k
atom/atom

:atom: The hackable text editor

JavaScriptnpmMIT Licenseatomeditor
atom.io
60.8k17.2k
marktext/marktext

📝A simple and elegant markdown editor, available for Linux, macOS and Windows.

TypeScriptnpmMIT Licensemacostypewriter-mode
marktext.me
59k4.4k
laurent22/joplin

Joplin - the privacy-focused note taking app with sync capabilities for Windows, macOS, Linux, Android and iOS.

TypeScriptnpmOtherreact-nativenodejs
joplinapp.org
55.7k6.2k
agalwood/Motrix

A full-featured download manager.

JavaScriptnpmMIT Licensemotrixaria2
motrix.app
52.3k4.9k
lyswhut/lx-music-desktop

一个基于 Electron 的音乐软件

TypeScriptnpmApache License 2.0music-playerjavascript
lyswhut.github.io/lx-music-doc/
52.2k6.9k
upscayl/upscayl

🆙 Upscayl - #1 Free and Open Source AI Image Upscaler for Linux, MacOS and Windows.

TypeScriptnpmGNU Affero General Public License v3.0aiesrgan
upscayl.org
47.4k2.4k
siyuan-note/siyuan

A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang.

TypeScriptnpmGNU Affero General Public License v3.0note-takinglocal-first
b3log.org/siyuan
45.3k2.9k
GitSquared/edex-ui

A cross-platform, customizable science fiction terminal emulator with advanced monitoring & touchscreen support.

JavaScriptnpmGNU General Public License v3.0terminalscience-fiction
45k3.2k