Skip to content

Conversation

softworkz
Copy link
Contributor

This PR includes all the the changes that have been discussed in Taking it to the Next Level!

I haven't updated any documentation yet. This PR - for now - is focused on getting everybody a quick start without much hazzle. I have even checked in the current nuget packages, in order to get the hurdle of building and consuming out of the way.

Quick Start Instructions

Warning

IMPORTANT: You must do a fresh checkout. Either clone into a new directory or - after checking out the branch, delete ALL files in the repo except the .git folder and then do a git reset.

  • Then, open the solution in Visual Studio
  • In Solution Explorer, expand: ElectronNET.WebApp >> Dependencies >> npm (ElectronHostHook....)
  • Right-click and choose "Restore", wait a few moments
  • Rebuild the solution
  • Ensure ElectronNET.WebApp is the startup project
  • Start debugging (F5 or click 'ASP.Net (unpackaged)'

Run on WSL

Prerequisites

  • Node 22 LTS needs to be installed
  • .NET8 SDK needs to be installed
    (but I think the ASP.Net core framework does the installation automatically when you start debugging)

To launch Debugging on WSL

  • Open the project properties for the ElectronNET.WebApp
  • After electron and builder version selection, find the "Target Runtime Identifier" and select linux-x64
  • From the dropdown button for debug target selection (with the green 'play' icon) select WSL
  • Click it

Creating Packages

  • Right-click project
  • Choose "Publish"
  • Choose one of the existing publish profiles (win-x64 or linux-x64) from the selection at the top
  • Hit "Publish"

Please let me know how it works for you

Enjoy!

- Update all packages to their latest version
- Drop tslint (replaced by eslint)
- Update node types to 22 => nodejs => 22 is minimum now
- Also use latest TypeScript version
- Finally, reference ElectronHostHook has a package dependency
  this avoids conflicts of dependency versions between main code
  and host-hook code, by letting npm resolve them
- Consume host-hook as a module
- Use package.json instead of electron-manifest.json
- Support new commandline flags:
  - unpackedelectron
    running in debug mode, electron first, so must launch dotnet
  - unpackeddotnet
    running in debug mode, dotnet first, do not launch dotnet
  - dotnetpacked
    running from electron-builder output, dotnet first, do not launch
  - {none of the above flags}
    running from electron-builder output, electron first, launch dotnet
  - electronforcedport
    specified by dotnet when dotnet-first, port is validated to be free
- Removed 'watch' functionality (regular debugging is working now)
- New feature to load a custom_main.js file, if present
- Removed the 'electronWebPort' handling
  When ASP.Net is launched first, then the information which port it
  should use would be coming too late; anyway, there's no need for
  letting the port number round-trip all the way through the manifest
  file, loaded by main.js and then sent to dotnet.
- Reworked handling of 'quit' message
This probably stems from newer ts definition or the newer ts version.
It errored because it cannot determine the event name and so it
considers argv[] as empty.
The crashed event has been removed in Electron 29 - just let TS ignore
that error
These were too short when debugging on WSL
- Add a ElectronNetDevMode property at the top
  This allows switching the project between using the nuget packages
  and consuming the core code directly via project references and
  direct imports or .props and .targets files
- Add the project data which was previously in the manifest file
- Add the Microsoft.TypeScript.MSBuild package
  This overrides the ASP.Net built-in TS support which is currently
  at version 5.6 only. With this package, we get 5.9.3 everywhere, so
  everything is consistent now.
  The only caveat is that it requires exclusion of folders (especially
  node_modules), so that they don't get attempted to be compiled
@FlorianRappl
Copy link
Collaborator

OK, looks great. Can we fix the NUKE project? You can forget about AppVeyor (we should finally remove it). Thanks!

@agracio
Copy link

agracio commented Oct 13, 2025

Minor suggestions to make solution compatible with other IDEs such as VSCode or JetBrains Rider as well as plain dotnet commands.

  • Exclude ElectronNET.Host project from solution, otherwise solution fails in dotnet restore, dotnet build as well as VSCode and Rider.
  • global.json has a fixed SDK version and fails when using dotnet commands and VSCode since it requires specific minor version 316.

@softworkz
Copy link
Contributor Author

OK, looks great. Can we fix the NUKE project? You can forget about AppVeyor (we should finally remove it). Thanks!

Alright, will do!

@softworkz
Copy link
Contributor Author

softworkz commented Oct 13, 2025

Minor suggestions to make solution compatible with other IDEs such as VSCode or JetBrains Rider as well as plain dotnet commands.

  • Exclude ElectronNET.Host project from solution, otherwise solution fails in dotnet restore, dotnet build as well as VSCode and Rider.

I wouldn't want to exclude it because it's a crucial part and it's not going to be worked on by many users (consuming users of Electron.NET won't normally touch it).
That being said, here are my thoughts/questions:

  • The Host project is using the age-old web "project" which isn't really a project at all - it has no project file and the little project-level data it has is stored in the solution file - which makes me wonder:
    • Does dotnet build really fail? I wouldn't expect it to support this kind of "projects"
    • Same question about Rider? Last time I checked, it didn't seem to be able to load .sln files (but I could be wrong)
  • With command line dotnet, you do not need to specify the .sln file - you can simple build the ElectronNET.AspNet project and the ElectronNET project separately. The latter depends on the other three, so they'll get built as well
  • Finally, one can always do a copy of the sln file, remove the Host project and gitignore it locally

Eventually it might make sense to migrate it to a TypeScript SDK project, the bit advantage here is not the TypeScript compilation (you can get that in many ways) but the fact that it bring the VSCode JS debugger under the hood. This allows you to do a multi-project debugging startup configuration where the TypeScript project attaches to the Node debugging interface or the Chromium debugging port (or both) and then you can get seamless debugging between dotnet code, node js code and browser js code.
I have achieved something similar for WebView2 in a WinUI3 application some time ago: WebView2 JavaScript Debugging in Visual Studio with Hot Reload

@softworkz
Copy link
Contributor Author

  • global.json has a fixed SDK version and fails when using dotnet commands and VSCode since it requires specific minor version 316.

Only as a minimum. rollForward is set to patch - not disable.

The reason for adding this is that we have seen a number of weird issues in our Azure DevOps builds. In all cases, the outcome (after painful research) was that their runner images had removed older SDKs and our net6 projects got build with a .net 9 SDK. In the past (earlier .net versions), such issues were extremely rare, but unfortinately, the situation has changed now.
We've added this kind of pinning to most of the important builds now, because when the right SDK won't be available, the builds will at least fail with a clear and actionable error message instaed of exposing inexplicable behavior.

It doesn't need to be 316, though. We can change it to 8.0.100 (first non-prerelease SDK).

@agracio
Copy link

agracio commented Oct 13, 2025

Just wanted to reiterate that these are very minor problems and are not a priority, full response below:

  • Does dotnet build really fail? I wouldn't expect it to support this kind of "projects"
  • Same question about Rider? Last time I checked, it didn't seem to be able to load .sln files (but I could be wrong)

dotnet build, dotnet restore, VSCode and Rider all fail with same exception:

C:\Dev\ElectronNET-electronnet_core\src\ElectronNET.sln : Solution file error MSB4249: Unable to build website  project "ElectronNET.Host". The ASP.NET compiler is only available on the .NET Framework version of MSBuild.

Rider workaround: unloading ElectronNET.Host project from solution same action as you can do in Visual Studio.
For dotnet the only solution would be to build individual projects.

Unfortunately for VSCode things become very messy, commenting out the project does not work as it is referenced in multiple places.

As I mentioned before these are very minor problems and since I work in Rider its pretty much a no issue.
Was mainly concerned for other potentials developers that use VSCode as main IDE.

Additionally dotnet commands fail as it is unable to find specific SDK while both VSCode and Rider are able to work around the issue. Unfortunately this also happens when targeting individual project instead of solution.

dotnet SDK error:

C:\Dev\ElectronNET-electronnet_core\src (electronnet_core -> origin)
dotnet build ElectronNET.WebApp/ElectronNET.WebApp.csproj
The command could not be loaded, possibly because:
  * You intended to execute a .NET application:
      The application 'build' does not exist.
  * You intended to execute a .NET SDK command:
      A compatible .NET SDK was not found.

Requested SDK version: 8.0.316
global.json file: C:\Dev\ElectronNET-electronnet_core\src\global.json

Installed SDKs:
1.1.14 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.526 [C:\Program Files\dotnet\sdk]
3.1.426 [C:\Program Files\dotnet\sdk]
5.0.104 [C:\Program Files\dotnet\sdk]
6.0.321 [C:\Program Files\dotnet\sdk]
7.0.410 [C:\Program Files\dotnet\sdk]
8.0.205 [C:\Program Files\dotnet\sdk]
8.0.206 [C:\Program Files\dotnet\sdk]
8.0.414 [C:\Program Files\dotnet\sdk]
9.0.305 [C:\Program Files\dotnet\sdk]

Install the [8.0.316] .NET SDK or update [C:\Dev\ElectronNET-electronnet_core\src\global.json] to match an installed SDK.

Learn about SDK resolution:
https://aka.ms/dotnet/sdk-not-found

- Remove obsolete sample targets
- Restore and build solution (.Lean) instead of projects
- Read version from common.props, compare with latest changelog version
  and fail if not equal
- Keep PostFix separate from version (AssemblyVersion may not have
  a postfix), so the postfix will go into the package version and
  file name as well as the informational version (visible in file
  properties dialog on Windows)
- Add "ElectronNET.Core " as prefix to GitHub release names (to
  disambiguate with earlier versions)
@softworkz
Copy link
Contributor Author

Additionally dotnet commands fail as it is unable to find specific SDK while both VSCode and Rider are able to work around the issue. Unfortunately this also happens when targeting individual project instead of solution.

@agracio - Thanks for that output! You were right, it didn't roll forward because setting rollForward to 'patch' doe not cross the feature bands (i.e. 100s 300s or 400s are kept separate).
I have changed rollForward now to 'feature' and the minimum to 305, so it shouldn't error out anymore (unless you have an age-old 8.0 SDK).

Solution file error MSB4249: Unable to build website project "ElectronNET.Host".

I have added a second solution file now: ElectronNET.Lean.sln
It only contains the projects relevant for building and it's not just a 2nd class workaround, because the Nuke build is using that solution itself.

Thanks for sharing your concerns, it was even more helpful than you might think!
(I got a number of global.json files to update... 😆 )

@softworkz
Copy link
Contributor Author

softworkz commented Oct 13, 2025

OK, looks great. Can we fix the NUKE project? You can forget about AppVeyor (we should finally remove it). Thanks!

Done! I hope you're okay withe the way I've done it. I needed to find some middle ground which (hopefully) satisfies all sides, because until everything is settled, I still need to be able to create versioned packages for your private feed without any delay, so I kept the version source inside common.props while nuke is reading this one plus the version from the changelog and fails when not equal. I also preserved the ability of postfixing the version for pre-release etc.

For restoring, building and packing, I switched to using an (extra) sln file - once for simplicity, but also because restoring interdependent projects separately can cause problems (you haven't had such dependencies before, hence it was fine).

PS: Yes, getting rid of that AppVeyor check would be cool - seeing all green is much nicer 😉

@FlorianRappl
Copy link
Collaborator

@GregorBiswanger do you have access to AppVeyor (in particular the registration for ElectronNET)? Would be cool to delete the web hook there. Just let me know.

Otherwise I would merge this in - so if there are any concerns or required enhancements let me know.

@agracio
Copy link

agracio commented Oct 14, 2025

Solution looks a lot cleaner with ElectronNET.Lean.sln, very minor observations that are not necessarily have to be addressed.

  • Is '!Config' project name intended to have ! in it's name or is it a typo?
  • Lean solution does not have any run configurations.
  • src/ElectronNET/build/ElectronNET.Build.dll is committed to the repository causing it to change state to modified after build, it should probably be removed from repo.

@agracio
Copy link

agracio commented Oct 14, 2025

Additionally while I am aware that Wiki is very fresh and is incomplete 'Getting Started -> With ASP.Net' has incorrect code at least in my experience following the guide.

I ended up combining original Program.cs code that loads Razor pages with Wiki code. Wiki code is trying to load Controller and Views that do not exist in a freshly created project.

This is my code for starting freshly created webapp.

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

var builder = WebApplication.CreateBuilder(args);

// Enable Electron.NET with callback for UI setup
builder.WebHost.UseElectron(args, ElectronAppReady);

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

var app = builder.Build();

// Configure the HTTP request pipeline
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    app.UseHsts();
}

app.UseHttpsRedirection();

app.UseRouting();

app.UseAuthorization();

app.MapStaticAssets();
app.MapRazorPages()
    .WithStaticAssets();

app.Run();

// Electron initialization callback
async Task ElectronAppReady()
{
    var browserWindow = await Electron.WindowManager.CreateWindowAsync(
        new BrowserWindowOptions
        {
            Width = 1200,
            Height = 800,
            Show = false,
            WebPreferences = new WebPreferences
            {
                NodeIntegration = false,
                ContextIsolation = true
            }
        });

    // Load your ASP.NET application, make sure to match port number in launchSettings.json
    await browserWindow.WebContents.LoadURLAsync("http://localhost:8001");

    browserWindow.OnReadyToShow += () => browserWindow.Show();
}

@FlorianRappl FlorianRappl merged commit 82814d9 into ElectronNET:develop Oct 14, 2025
2 of 3 checks passed
@softworkz
Copy link
Contributor Author

@agracio - Thanks a lot for the feedback!

  • Is '!Config' project name intended to have ! in it's name or is it a typo?

Yea, it's intended - it't a cheap trick to keep it at the top 😜
(it's a solution folder, not a project)

  • Lean solution does not have any run configurations.

All projects are class libraries. There's nothing to run..?

  • src/ElectronNET/build/ElectronNET.Build.dll is committed to the repository causing it to change state to modified after build, it should probably be removed from repo.

Maybe I was a bit overprotective here. I included it because all other outputs which go into the packages are part of the repo, including compilation output (like all the .js files from TypeScript compilation), so that nothing can go wrong and things are just "working".
For example, when you flip the switch in the demo projects to consume the project content instead of nuget packages, the build dll needs to be at this place on project load already. For similar reasons, I have included the 0.0.18 packages, so that you can play with everything right when opening for the first time.
Eventually, we can drop all this and rely on compilation and package creation by people working with it.

Thanks

@FlorianRappl
Copy link
Collaborator

Just FYI @softworkz: The publish failed as the currently assigned NuGet key is missing the new package. I am in contact with @GregorBiswanger and we will update / fix this ASAP.

I will trigger a re-build to publish the preview of the package once this is done.

@softworkz
Copy link
Contributor Author

Thanks! I'm currently reviewing the docs and PR them shortly.

@softworkz
Copy link
Contributor Author

softworkz commented Oct 15, 2025

'Getting Started -> With ASP.Net' has incorrect code at least in my experience following the guide.

You're right, AI had found that it should get a little creative about that code, even though, I had already provided the snippet I wanted to have in the rough draft I had prepared before:

0c5cc3b (#895)

Anyway, it's fixed in the new PR now.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants