-
-
Notifications
You must be signed in to change notification settings - Fork 736
Startup Methods
ElectronNET.Core supports multiple startup methods to handle different development and deployment scenarios. The framework automatically detects the appropriate mode based on command-line flags and environment.
The framework supports 8 different launch scenarios covering every combination of:
- Packaged vs Unpackaged deployment
- Console vs ASP.NET application types
- Dotnet-first vs Electron-first initialization
# Launch Electron first, which then starts .NET
node node_modules/electron/cli.js main.js -unpackedelectron# Launch .NET first, which then starts Electron
dotnet run -unpackeddotnet# Run packaged app with .NET starting first
MyApp.exe -dotnetpacked# Run packaged app with Electron starting first
MyApp.exe- Use Case: Debug Electron main process and Node.js code
-
Command:
-unpackedelectronflag -
Process Flow:
- Electron starts first
- Electron launches .NET process
- .NET connects back to Electron
- Application runs with Electron in control
- Use Case: Debug ASP.NET/C# code with Hot Reload
-
Command:
-unpackeddotnetflag -
Process Flow:
- .NET application starts first
- .NET launches Electron process
- Electron connects back to .NET
- Application runs with .NET in control
- Use Case: Deployed application with .NET controlling lifecycle
-
Command:
-dotnetpackedflag -
Process Flow:
- .NET executable starts first
- .NET launches Electron from packaged files
- Electron loads from app.asar or extracted files
- .NET maintains process control
- Use Case: Traditional Electron app behavior
- Command: No special flags
-
Process Flow:
- Electron executable starts first
- Electron launches .NET from packaged files
- .NET runs from Electron's process context
- Electron maintains UI control
// Program.cs
var builder = WebApplication.CreateBuilder(args);
// Configure for different startup modes
builder.WebHost.UseElectron(args, async () =>
{
var browserWindow = await Electron.WindowManager.CreateWindowAsync(
new BrowserWindowOptions { Show = false });
await browserWindow.WebContents.LoadURLAsync("http://localhost:8001");
browserWindow.OnReadyToShow += () => browserWindow.Show();
});
var app = builder.Build();
app.Run();// Program.cs
public static async Task Main(string[] args)
{
var runtimeController = ElectronNetRuntime.RuntimeController;
await runtimeController.Start();
await runtimeController.WaitReadyTask;
await InitializeApplication();
await runtimeController.WaitStoppedTask;
}
The image above illustrates how each combination of deployment type, application type, and initialization order affects the process lifecycle.
ASP.NET-First Debugging (Recommended)
// launchSettings.json
{
"ASP.Net (unpackaged)": {
"commandName": "Project",
"commandLineArgs": "-unpackeddotnet"
}
}Electron-First Debugging
// launchSettings.json
{
"Electron (unpackaged)": {
"commandName": "Executable",
"executablePath": "node",
"commandLineArgs": "node_modules/electron/cli.js main.js -unpackedelectron"
}
}Dotnet-First Deployment
# Build and package
dotnet publish -c Release -r win-x64
cd publish\Release\net8.0\win-x64
npm install
npx electron-builder
# Run with dotnet-first
MyApp.exe -dotnetpackedElectron-First Deployment (Default)
# Run packaged application (no special flags needed)
MyApp.exeElectronNET.Core automatically manages process lifecycle:
- Graceful shutdown when main window is closed
- Proper cleanup of child processes
- Error handling for process failures
- Cross-platform compatibility for process management
Access runtime controller for advanced scenarios:
var runtime = ElectronNetRuntime.RuntimeController;
// Wait for Electron to be ready
await runtime.WaitReadyTask;
// Stop Electron runtime
await runtime.Stop();
await runtime.WaitStoppedTask;"Electron process not found"
- Ensure Node.js 22.x is installed
- Check that .NET build succeeded
- Verify RuntimeIdentifier is set correctly
"Port conflicts"
- Use different ports for different startup modes
- Check that no other instances are running
- Verify firewall settings
"Process won't terminate"
- Use dotnet-first mode for better cleanup
- Check for unhandled exceptions
- Verify all windows are properly closed
- Development: Use .NET-first for C# debugging, Electron-first for Node.js debugging
- Production: Use .NET-first for better process control, Electron-first for traditional behavior
- Cross-platform: Use .NET-first for consistent behavior across platforms
<!-- .csproj -->
<PropertyGroup>
<ElectronNETCoreEnvironment>Production</ElectronNETCoreEnvironment>
</PropertyGroup>- Debugging - Debug different startup modes
- Package Building - Package for different deployment scenarios
- Migration Guide - Update existing apps for new startup methods
The flexible startup system ensures ElectronNET.Core works optimally in every scenario while providing the control and debugging experience .NET developers expect. Choose the appropriate mode based on your development workflow and deployment requirements.
Want to contribute to this documentation? Please fork and create a PR! The Wiki is autogenerated from the /docs content in the repository.