Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 746
Console App
A major benefit in ElectronNET.Core is the ability to build Electron applications using simple console applications instead of requiring ASP.NET Core. This removes a significant barrier and enables many more use cases.
Console applications with ElectronNET.Core support multiple content scenarios:
- File System HTML/JS - Serve static web content directly from the file system
- Remote Server Integration - Connect to existing web servers or APIs
- Lightweight Architecture - Avoid ASP.NET overhead when not needed
- Simplified Deployment - Package and distribute with minimal dependencies
See System Requirements.
Create a new console application in Visual Studio by selecting New Project and choosing one of the project templates for console apps.
dotnet new console -n MyElectronApp cd MyElectronAppdotnet add package ElectronNET.CoreNote
The API package is automatically included as a dependency of ElectronNET.Core.
Add the Electron.NET configuration to your .csproj file:
<PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net10.0</TargetFramework> <RuntimeIdentifier>win-x64</RuntimeIdentifier> </PropertyGroup> <ItemGroup> <PackageReferenceInclude="ElectronNET.Core"Version="0.4.0" /> </ItemGroup>Warning
Specifying OutputType property is crucial in order to get the ability of WSL debugging. Especially it is not included in ASP.NET projects.
When you migrate from ASP.NET to a console application, be sure to add this to the project file.
Here's a complete console application example:
usingSystem;usingSystem.Threading.Tasks;usingElectronNET.API.Entities;namespaceMyElectronApppublicclassProgram{publicstaticasyncTaskMain(string[]args){varruntimeController=ElectronNetRuntime.RuntimeController;try{// Start Electron runtimeawaitruntimeController.Start();awaitruntimeController.WaitReadyTask;// Initialize your Electron appawaitInitializeApp();// Wait for shutdownawaitruntimeController.WaitStoppedTask.ConfigureAwait(false);}catch(Exceptionex){Console.WriteLine($"Error: {ex.Message}");awaitruntimeController.Stop().ConfigureAwait(false);awaitruntimeController.WaitStoppedTask.WaitAsync(TimeSpan.FromSeconds(2)).ConfigureAwait(false);}}privatestaticasyncTaskInitializeApp(){// Create main windowvarbrowserWindow=awaitElectron.WindowManager.CreateWindowAsync(newBrowserWindowOptions{Show=false,WebPreferences=newWebPreferences{// Add these two when using file:// URLsWebSecurity=false,AllowRunningInsecureContent=true,NodeIntegration=false,ContextIsolation=true}});// Load your content (file system, remote URL, etc.)awaitbrowserWindow.WebContents.LoadURLAsync("https://example.com");// Show window when readybrowserWindow.OnReadyToShow+=()=>browserWindow.Show();}}Serve HTML/JS files from your project:
// In your project root, create wwwroot/index.htmlvarfileInfo=newFileInfo(Environment.ProcessPath);varexeFolder=fileInfo.DirectoryName;varhtmlPath=Path.Combine(exeFolder,"wwwroot/index.html");varurl=newUri(htmlPath,UriKind.Absolute);awaitbrowserWindow.WebContents.LoadFileAsync(url.ToString());Load content from any web server:
awaitbrowserWindow.WebContents.LoadURLAsync("https://your-server.com/app");- Debugging - Learn about debugging console applications
- Package Building - Create distributable packages
- Migration Guide - Moving from ASP.NET projects
✅ Simpler Architecture - No ASP.NET complexity when not needed
✅ Flexible Content - Use any HTML/JS source
✅ Faster Development - Less overhead for simple applications
✅ Easy Deployment - Minimal dependencies
✅ Better Performance - Lighter weight than full web applications
Want to contribute to this documentation? Please fork and create a PR! The Wiki is autogenerated from the /docs content in the repository.