Skip to content

Console App

github-actions[bot] edited this page Dec 18, 2025 · 6 revisions

Console Application Setup

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.

🎯 What You Can Build

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

📋 Prerequisites

See System Requirements.

🚀 Quick Start

1. Create Console Application

Visual Studio

Create a new console application in Visual Studio by selecting New Project and choosing one of the project templates for console apps.

From the command line

dotnet new console -n MyElectronApp cd MyElectronApp

2. Install NuGet Packages

dotnet add package ElectronNET.Core

Note

The API package is automatically included as a dependency of ElectronNET.Core.

3. Configure Project File

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.

4. Implement Basic Structure

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();}}

📁 Content Sources

File System Content

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());

Remote Content

Load content from any web server:

awaitbrowserWindow.WebContents.LoadURLAsync("https://your-server.com/app");

🚀 Next Steps

💡 Benefits of Console Apps

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

Clone this wiki locally