MIT License

项目介绍

ElectronNET/Electron.NET 是一个托管在 GitHub 上的开源项目,主要使用 C# 编写,采用 MIT License 许可证,目前获得 7.6k 个 Star、743 次 Fork。

仓库全名
ElectronNET/Electron.NET
开源许可证
MIT License
Star 数
7.6k
Fork 数
743
未关闭 Issue
8

README 摘要

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…

完整内容见 GitHub 原始 README 或本页 。

常见问题

Electron.NET 用什么语言开发?

主要使用 C# 编写,采用 MIT License 许可证,目前有 7.6k 个 Star。

Electron.NET 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 Electron.NET 的源码?

可以直接克隆仓库:git clone https://github.com/ElectronNET/Electron.NET.git,默认分支为 main;安装与运行步骤见仓库 README。

Electron.NET 最近还在维护吗?

仓库最近一次更新为 2 天前,当前有 8 个未关闭 Issue;Star 数为 7.6k,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

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

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

语言占比

Batchfile
C#
CSS
HTML
JavaScript
PowerShell
Python
Shell
TypeScript

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
  • ElectronNET.Core.Templates: 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:

Or just buy Florian a coffee :coffee:.

Any support appreciated! 🍻

🎉 License

MIT-licensed. See LICENSE for details.

Enjoy!

评论

暂无评论