Can't run App after Publish - Just opens command prompt #963

Closed
opened 2026-01-29 16:52:58 +00:00 by claunia · 1 comment
Owner

Originally created by @aherrick on GitHub (Oct 11, 2024).

I have a simple Blazor Server .NET 8 App that I'm trying to publish. When I run it in development mode it has no issues.

When I attempt to publish and run in Production I see the following. Am I doing something wrong here?

Published Folder:

2024-10-11_11-04-02

Error when trying to run EXE in BIN folder:

2024-10-11_11-05-02

Below is my Program.cs code:

using ElectronNET.API;
using ElectronNET.API.Entities;

var builder = WebApplication.CreateBuilder(args);

builder.WebHost.UseElectron(args);

// Add services to the container.
builder.Services.AddRazorComponents().AddInteractiveServerComponents();

var app = builder.Build();

// Configure the HTTP request pipeline.
//if (!app.Environment.IsDevelopment())
//{
//    app.UseExceptionHandler("/Error", createScopeForErrors: true);
//    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
//    app.UseHsts();
//}

//app.UseHttpsRedirection();

app.UseStaticFiles();
app.UseAntiforgery();

app.MapRazorComponents<BlazorTron.Components.App>().AddInteractiveServerRenderMode();

/// Electron Fun ///

await app.StartAsync();

var menu = new MenuItem[]
{
    new()
    {
        Label = "File",
        Type = MenuType.submenu,
        Submenu =
        [
            new MenuItem { Role = MenuRole.about },
            new MenuItem { Type = MenuType.separator },
            new MenuItem { Role = MenuRole.quit }
        ]
    },
};

Electron.Menu.SetApplicationMenu(menu);

var browserWindow = await Electron.WindowManager.CreateWindowAsync(
    new BrowserWindowOptions
    {
        Width = 800,
        Height = 600,
        Show = false
    }
);

await browserWindow.WebContents.Session.ClearCacheAsync();

browserWindow.OnMinimize += () =>
{
    MinimizeNotification();

    browserWindow.Hide();
};

// setup tray
await Electron.Tray.Show(
    Path.Combine(Environment.CurrentDirectory, "./wwwroot/favicon.png"),
    [
        .. new List<MenuItem>
        {
            new() { Label = "Show", Click = browserWindow.Show },
            new() { Label = "Exit", Click = browserWindow.Close }
        }
    ]
);

await Electron.Tray.SetToolTip("BlazorTron!");

Electron.Tray.OnDoubleClick += (_, _) =>
{
    browserWindow.Show();
};

MinimizeNotification();

static void MinimizeNotification()
{
    Electron.Tray.DisplayBalloon(
        new DisplayBalloonOptions() { Title = "BlazorTron!", Content = "Chilling in your tray..." }
    );
}

app.WaitForShutdown();

https://github.com/aherrick/BlazorTron

Originally created by @aherrick on GitHub (Oct 11, 2024). I have a simple Blazor Server .NET 8 App that I'm trying to publish. When I run it in development mode it has no issues. When I attempt to publish and run in Production I see the following. Am I doing something wrong here? Published Folder: ![2024-10-11_11-04-02](https://github.com/user-attachments/assets/7c3e2eb8-b932-44d0-bdc7-3a6a006ce6bf) Error when trying to run EXE in BIN folder: ![2024-10-11_11-05-02](https://github.com/user-attachments/assets/78d1a09d-b99a-4d25-9486-669245732ac6) Below is my Program.cs code: ``` using ElectronNET.API; using ElectronNET.API.Entities; var builder = WebApplication.CreateBuilder(args); builder.WebHost.UseElectron(args); // Add services to the container. builder.Services.AddRazorComponents().AddInteractiveServerComponents(); var app = builder.Build(); // Configure the HTTP request pipeline. //if (!app.Environment.IsDevelopment()) //{ // app.UseExceptionHandler("/Error", createScopeForErrors: true); // // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. // app.UseHsts(); //} //app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseAntiforgery(); app.MapRazorComponents<BlazorTron.Components.App>().AddInteractiveServerRenderMode(); /// Electron Fun /// await app.StartAsync(); var menu = new MenuItem[] { new() { Label = "File", Type = MenuType.submenu, Submenu = [ new MenuItem { Role = MenuRole.about }, new MenuItem { Type = MenuType.separator }, new MenuItem { Role = MenuRole.quit } ] }, }; Electron.Menu.SetApplicationMenu(menu); var browserWindow = await Electron.WindowManager.CreateWindowAsync( new BrowserWindowOptions { Width = 800, Height = 600, Show = false } ); await browserWindow.WebContents.Session.ClearCacheAsync(); browserWindow.OnMinimize += () => { MinimizeNotification(); browserWindow.Hide(); }; // setup tray await Electron.Tray.Show( Path.Combine(Environment.CurrentDirectory, "./wwwroot/favicon.png"), [ .. new List<MenuItem> { new() { Label = "Show", Click = browserWindow.Show }, new() { Label = "Exit", Click = browserWindow.Close } } ] ); await Electron.Tray.SetToolTip("BlazorTron!"); Electron.Tray.OnDoubleClick += (_, _) => { browserWindow.Show(); }; MinimizeNotification(); static void MinimizeNotification() { Electron.Tray.DisplayBalloon( new DisplayBalloonOptions() { Title = "BlazorTron!", Content = "Chilling in your tray..." } ); } app.WaitForShutdown(); ``` https://github.com/aherrick/BlazorTron
claunia added the bug label 2026-01-29 16:52:58 +00:00
Author
Owner

@aherrick commented on GitHub (Oct 11, 2024):

I figured this out - I was looking in the wrong spot: it publishes to:

\BlazorTron\bin\Desktop\win-unpacked

@aherrick commented on GitHub (Oct 11, 2024): I figured this out - I was looking in the wrong spot: it publishes to: `\BlazorTron\bin\Desktop\win-unpacked`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#963