Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Console App

github-actions[bot] edited this page May 25, 2026 · 8 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>
  <PackageReference Include="ElectronNET.Core" Version="0.5.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:

using System;
using System.Threading.Tasks;
using ElectronNET.API.Entities;

namespace MyElectronApp

public class Program
{
    public static async Task Main(string[] args)
    {
        var runtimeController = ElectronNetRuntime.RuntimeController;

        try
        {
            // Start Electron runtime
            await runtimeController.Start();
            await runtimeController.WaitReadyTask;

            // Initialize your Electron app
            await InitializeApp();

            // Wait for shutdown
            await runtimeController.WaitStoppedTask.ConfigureAwait(false);
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error: {ex.Message}");
            await runtimeController.Stop().ConfigureAwait(false);
            await runtimeController.WaitStoppedTask.WaitAsync(TimeSpan.FromSeconds(2)).ConfigureAwait(false);
        }
    }

    private static async Task InitializeApp()
    {
        // Create main window
        var browserWindow = await Electron.WindowManager.CreateWindowAsync(
            new BrowserWindowOptions
            {
                Show = false,
                WebPreferences = new WebPreferences
                {
                    // Add these two when using file:// URLs
                    WebSecurity = false,
                    AllowRunningInsecureContent = true,

                    NodeIntegration = false,
                    ContextIsolation = true
                }
            });

        // Load your content (file system, remote URL, etc.)
        await browserWindow.WebContents.LoadURLAsync("https://example.com");

        // Show window when ready
        browserWindow.OnReadyToShow += () => browserWindow.Show();
    }
}

πŸ“ Content Sources

File System Content

Serve HTML/JS files from your project:

// In your project root, create wwwroot/index.html
var fileInfo = new FileInfo(Environment.ProcessPath);
var exeFolder = fileInfo.DirectoryName;
var htmlPath = Path.Combine(exeFolder, "wwwroot/index.html");
var url = new Uri(htmlPath, UriKind.Absolute);
await browserWindow.WebContents.LoadFileAsync(url.ToString());

Remote Content

Load content from any web server:

await browserWindow.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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.