-
Notifications
You must be signed in to change notification settings - Fork 0
ASP.Net
ASP.NET Core remains the recommended approach for complex web applications with ElectronNET.Core, providing all the benefits of the ASP.NET ecosystem along with enhanced Electron integration.
- .NET 8.0 or later
- Node.js 22.x or later (Download here)
- Visual Studio 2022 (recommended) or other .NET IDE
- Windows 10/11 (x64, ARM64)
- macOS 11+ (Intel, Apple Silicon)
- Linux (most distributions with glibc 2.31+)
Note: For Linux development on Windows, install WSL2 to build and debug Linux packages.
Create a new ASP.NET Core Web App in Visual Studio:
dotnet new webapp -n MyElectronWebApp
cd MyElectronWebAppPM> Install-Package ElectronNET.Core
PM> Install-Package ElectronNET.Core.AspNetNote:
ElectronNET.Core.AspNetprovides ASP.NET-specific runtime components and should be used alongsideElectronNET.Core.
Update your Program.cs to enable Electron.NET:
using ElectronNET.API;
using ElectronNET.API.Entities;
var builder = WebApplication.CreateBuilder(args);
// Enable Electron.NET with callback for UI setup
builder.WebHost.UseElectron(args, ElectronAppReady);
// Add services to the container
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
// Electron initialization callback
async Task ElectronAppReady()
{
var browserWindow = await Electron.WindowManager.CreateWindowAsync(
new BrowserWindowOptions
{
Width = 1200,
Height = 800,
Show = false,
WebPreferences = new WebPreferences
{
NodeIntegration = false,
ContextIsolation = true
}
});
// Load your ASP.NET application
await browserWindow.WebContents.LoadURLAsync("https://localhost:7001");
browserWindow.OnReadyToShow += () => browserWindow.Show();
}For projects using the traditional Startup.cs pattern:
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseElectron(args, ElectronAppReady)
.UseStartup<Startup>();
// Electron callback (same as above)
async Task ElectronAppReady()
{
var browserWindow = await Electron.WindowManager.CreateWindowAsync(
new BrowserWindowOptions { Show = false });
await browserWindow.WebContents.LoadURLAsync("https://localhost:5001");
browserWindow.OnReadyToShow += () => browserWindow.Show();
}Configure Electron.NET through MSBuild properties in your .csproj:
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ElectronNETCoreDescription>My ASP.NET Electron App</ElectronNETCoreDescription>
<ElectronNETCoreDisplayName>MyApp</ElectronNETCoreDisplayName>
</PropertyGroup>Customize the main window appearance:
var options = new BrowserWindowOptions
{
Width = 1400,
Height = 900,
MinWidth = 800,
MinHeight = 600,
Frame = true,
TitleBarStyle = TitleBarStyle.Default,
Icon = "wwwroot/favicon.ico"
};Create additional windows for different parts of your application:
var settingsWindow = await Electron.WindowManager.CreateWindowAsync(
new BrowserWindowOptions
{
Width = 600,
Height = 400,
Parent = browserWindow,
Modal = true
},
"https://localhost:7001/settings");- Debugging - Learn about ASP.NET debugging features
- Package Building - Create distributable packages
- Startup Methods - Understanding launch scenarios
✅ Full Web Stack - Use MVC, Razor Pages, Blazor, and all ASP.NET features ✅ Hot Reload - Edit ASP.NET code and see changes instantly ✅ Rich Ecosystem - Access to thousands of ASP.NET packages ✅ Modern Development - Latest C# features and ASP.NET patterns ✅ Scalable Architecture - Build complex, maintainable applications
Want to contribute to this documentation? Please fork and create a PR! The Wiki is autogenerated from the /docs content in the repository.