AI-written docs

This commit is contained in:
softworkz
2025-10-14 09:52:44 +02:00
parent bb5779a941
commit 0c5cc3ba9d
9 changed files with 1482 additions and 209 deletions

View File

@@ -1,57 +1,190 @@
## 🛠 Requirements to Run
# ASP.NET Core Setup
Our API uses .NET 6/8, so our
ASP.NET Core remains the recommended approach for complex web applications with ElectronNET.Core, providing all the benefits of the ASP.NET ecosystem along with enhanced Electron integration.
Also you should have installed:
## 🛠 System Requirements
* .NET 6/8 or later
* OS
minimum base OS is the same as [.NET 6](https://github.com/dotnet/core/blob/main/release-notes/6.0/supported-os.md) / [.NET 8](https://github.com/dotnet/core/blob/main/release-notes/8.0/supported-os.md).
* NodeJS (at least [Version 22.x](https://nodejs.org))
### Required Software
- **.NET 8.0** or later
- **Node.js 22.x** or later ([Download here](https://nodejs.org))
- **Visual Studio 2022** (recommended) or other .NET IDE
### Supported Operating Systems
- **Windows 10/11** (x64, ARM64)
- **macOS 11+** (Intel, Apple Silicon)
- **Linux** (most distributions with glibc 2.31+)
## 👩‍🏫 Usage with ASP.Net
> **Note**: For Linux development on Windows, install [WSL2](https://docs.microsoft.com/windows/wsl/install) to build and debug Linux packages.
- Create a new ASP.Net Core project
- Install the following two nuget packages:
## 🚀 Quick Start
```ps1
### 1. Create ASP.NET Core Project
Create a new ASP.NET Core Web App in Visual Studio:
```bash
dotnet new webapp -n MyElectronWebApp
cd MyElectronWebApp
```
### 2. Install NuGet Packages
```powershell
PM> Install-Package ElectronNET.Core
PM> Install-Package ElectronNET.Core.AspNet
```
### Enable Electron.NET on Startup
> **Note**: `ElectronNET.Core.AspNet` provides ASP.NET-specific runtime components and should be used alongside `ElectronNET.Core`.
To do so, use the `UseElectron` extension method on a `WebApplicationBuilder`, an `IWebHostBuilder` or any descendants.
### 3. Configure Program.cs
> [!NOTE]
> New in Electron.NET Core is that you provide a callback method as an argument to `UseElectron()`, which ensures that you get to know the right moment to set up your application UI.
Update your `Program.cs` to enable Electron.NET:
### Program.cs
```csharp
```csharp
using ElectronNET.API;
using ElectronNET.API.Entities;
public static void Main(string[] args)
{
WebHost.CreateDefaultBuilder(args)
.UseElectron(args, ElectronAppReady)
.UseStartup<Startup>()
.Build()
.Run();
}
var builder = WebApplication.CreateBuilder(args);
public static async Task ElectronAppReady()
{
var browserWindow = await Electron.WindowManager.CreateWindowAsync(
new BrowserWindowOptions { Show = false });
// Enable Electron.NET with callback for UI setup
builder.WebHost.UseElectron(args, ElectronAppReady);
browserWindow.OnReadyToShow += () => browserWindow.Show();
}
// Add services to the container
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
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
await browserWindow.WebContents.LoadURLAsync("https://localhost:7001");
browserWindow.OnReadyToShow += () => browserWindow.Show();
}
```
### 4. Alternative: IWebHostBuilder Setup
For projects using the traditional `Startup.cs` pattern:
```csharp
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseElectron(args, ElectronAppReady)
.UseStartup<Startup>();
// Electron callback (same as above)
async Task ElectronAppReady()
{
var browserWindow = await Electron.WindowManager.CreateWindowAsync(
new BrowserWindowOptions { Show = false });
await browserWindow.WebContents.LoadURLAsync("https://localhost:5001");
browserWindow.OnReadyToShow += () => browserWindow.Show();
}
```
## 🔧 Configuration
### Project File Settings
Configure Electron.NET through MSBuild properties in your `.csproj`:
```xml
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ElectronNETCoreDescription>My ASP.NET Electron App</ElectronNETCoreDescription>
<ElectronNETCoreDisplayName>MyApp</ElectronNETCoreDisplayName>
</PropertyGroup>
```
## 🎨 Customization
### Window Configuration
Customize the main window appearance:
```csharp
var options = new BrowserWindowOptions
{
Width = 1400,
Height = 900,
MinWidth = 800,
MinHeight = 600,
Frame = true,
TitleBarStyle = TitleBarStyle.Default,
Icon = "wwwroot/favicon.ico"
};
```
### Multiple Windows
Create additional windows for different parts of your application:
```csharp
var settingsWindow = await Electron.WindowManager.CreateWindowAsync(
new BrowserWindowOptions
{
Width = 600,
Height = 400,
Parent = browserWindow,
Modal = true
},
"https://localhost:7001/settings");
```
## 🚀 Next Steps
- **[Debugging](Debugging.md)** - Learn about ASP.NET debugging features
- **[Package Building](Package-Building.md)** - Create distributable packages
- **[Startup Methods](Startup-Methods.md)** - Understanding launch scenarios
## 💡 Benefits of ASP.NET + Electron
**Full Web Stack** - Use MVC, Razor Pages, Blazor, and all ASP.NET features
**Hot Reload** - Edit ASP.NET code and see changes instantly
**Rich Ecosystem** - Access to thousands of ASP.NET packages
**Modern Development** - Latest C# features and ASP.NET patterns
**Scalable Architecture** - Build complex, maintainable applications

View File

@@ -1,13 +1,72 @@
// Understand this code so you can explain how to set it up with console project
# Console Application Setup
namespace ElectronNET.WebApp
One of the most significant breakthroughs in ElectronNET.Core is the ability to build Electron applications using simple console applications instead of requiring ASP.NET Core. This removes a major 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
Before starting, ensure you have:
- **.NET 8.0** or later
- **Node.js 22.x** or later
- **Visual Studio 2022** (recommended) or Visual Studio Code
## 🚀 Quick Start
### 1. Create Console Application
Create a new Console Application project in Visual Studio:
```bash
dotnet new console -n MyElectronApp
cd MyElectronApp
```
### 2. Install NuGet Packages
```powershell
PM> Install-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:
```xml
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ElectronNET.Core" Version="1.0.0" />
</ItemGroup>
```
### 4. Implement Basic Structure
Here's a complete console application example:
```csharp
using System;
using System.Threading.Tasks;
using ElectronNET.API.Entities;
namespace MyElectronApp
{
using System;
using System.Threading.Tasks;
using ElectronNET.API.Entities;
public class Program
{
public static async Task Main(string[] args)
@@ -16,37 +75,143 @@ namespace ElectronNET.WebApp
try
{
// Start Electron runtime
await runtimeController.Start();
await runtimeController.WaitReadyTask;
await ElectronBootstrap();
// Initialize your Electron app
await InitializeApp();
// Wait for shutdown
await runtimeController.WaitStoppedTask;
}
catch (Exception ex)
{
Console.WriteLine(ex);
await runtimeController.Stop().ConfigureAwait(false);
await runtimeController.WaitStoppedTask.WaitAsync(TimeSpan.FromSeconds(2)).ConfigureAwait(false);
Console.WriteLine($"Error: {ex.Message}");
await runtimeController.Stop();
await runtimeController.WaitStoppedTask.WaitAsync(TimeSpan.FromSeconds(2));
}
}
public static async Task ElectronBootstrap()
private static async Task InitializeApp()
{
//AddDevelopmentTests();
// Create main window
var browserWindow = await Electron.WindowManager.CreateWindowAsync(
new BrowserWindowOptions
{
Width = 1200,
Height = 800,
Show = false,
WebPreferences = new WebPreferences
{
NodeIntegration = false,
ContextIsolation = true
}
});
var browserWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions
{
Width = 1152,
Height = 940,
Show = false,
}, "https://github.com/ElectronNET/Electron.NET");
await browserWindow.WebContents.Session.ClearCacheAsync();
// 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:
```csharp
// In your project root, create wwwroot/index.html
await browserWindow.WebContents.LoadFileAsync("wwwroot/index.html");
```
### Remote Content
Load content from any web server:
```csharp
await browserWindow.WebContents.LoadURLAsync("https://your-server.com/app");
```
### Development Server
For development, you can run a simple HTTP server:
```csharp
// Add this for development
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
{
await browserWindow.WebContents.LoadURLAsync("http://localhost:3000");
}
```
## 🔧 Configuration Options
### Project Configuration
Configure Electron settings through MSBuild properties in your `.csproj`:
```xml
<PropertyGroup>
<ElectronNETCoreDescription>My Electron App</ElectronNETCoreDescription>
<ElectronNETCoreDisplayName>MyApp</ElectronNETCoreDisplayName>
<ElectronNETCoreAuthorName>Your Name</ElectronNETCoreAuthorName>
</PropertyGroup>
```
### Runtime Configuration
Access configuration at runtime:
```csharp
var app = await Electron.App.GetAppAsync();
Console.WriteLine($"App Name: {app.Name}");
```
## 🎨 Customization
### Window Options
Customize your main window:
```csharp
var options = new BrowserWindowOptions
{
Width = 1400,
Height = 900,
MinWidth = 800,
MinHeight = 600,
Frame = true,
Title = "My Custom App",
Icon = "assets/app-icon.png"
};
```
### Multiple Windows
Create additional windows as needed:
```csharp
var settingsWindow = await Electron.WindowManager.CreateWindowAsync(
new BrowserWindowOptions { Width = 600, Height = 400, Modal = true },
"app://settings.html");
```
## 🚀 Next Steps
- **[Debugging](Debugging.md)** - Learn about debugging console applications
- **[Package Building](Package-Building.md)** - Create distributable packages
- **[Migration Guide](../Core/Migration-Guide.md)** - Moving from ASP.NET projects
## 💡 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

View File

@@ -1,14 +1,16 @@
# Debugging
ElectronNET.Core transforms the debugging experience by providing native Visual Studio integration with multiple debugging modes. No more complex setup or manual process attachment—debugging now works as expected for .NET developers.
explain the ease of debugging and everything from what you've already read.
## 🎯 Debugging Modes
ElectronNET.Core supports three main debugging approaches, all configured through Visual Studio's launch profiles:
This config enables all three possible ways for unpackaged debugging:
### 1. ASP.NET-First Debugging (Recommended)
Debug your .NET code directly with full Hot Reload support:
The first and last are working by default (newly created prject). The 2nd one needs to the added manually, if desired.
```json
{
"profiles": {
"ASP.Net (unpackaged)": {
@@ -16,7 +18,83 @@ The first and last are working by default (newly created prject). The 2nd one ne
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:8001/"
"applicationUrl": "https://localhost:7001/"
}
}
}
```
**Benefits:**
- ✅ Full C# debugging with breakpoints
- ✅ Hot Reload for ASP.NET code
- ✅ Edit-and-continue functionality
- ✅ Native Visual Studio debugging experience
### 2. Electron-First Debugging
Debug the Electron process when you need to inspect native Electron APIs:
```json
{
"profiles": {
"Electron (unpackaged)": {
"commandName": "Executable",
"executablePath": "node",
"commandLineArgs": "node_modules/electron/cli.js main.js -unpackedelectron",
"workingDirectory": "$(TargetDir).electron",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
```
**Benefits:**
- ✅ Debug Electron main process
- ✅ Inspect native Electron APIs
- ✅ Node.js debugging capabilities
### 3. Cross-Platform WSL Debugging
Debug Linux builds directly from Windows Visual Studio:
```json
{
"profiles": {
"WSL": {
"commandName": "WSL2",
"launchUrl": "http://localhost:7001/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:7001/"
},
"distributionName": ""
}
}
}
```
**Benefits:**
- ✅ Debug Linux applications from Windows
- ✅ Test Linux-specific behavior
- ✅ Validate cross-platform compatibility
## 🔧 Setup Instructions
### 1. Configure Launch Settings
Add the debugging profiles to `Properties/launchSettings.json`:
```json
{
"profiles": {
"ASP.Net (unpackaged)": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:7001/"
},
"Electron (unpackaged)": {
"commandName": "Executable",
@@ -29,15 +107,130 @@ The first and last are working by default (newly created prject). The 2nd one ne
},
"WSL": {
"commandName": "WSL2",
"launchUrl": "http://localhost:8001/",
"launchUrl": "http://localhost:7001/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:8001/"
"ASPNETCORE_URLS": "http://localhost:7001/"
},
"distributionName": ""
}
}
}
```
Important: The runtime identifier needs to be changed in the project when switching between Windows and WSL.
### 2. Switch Runtime Identifiers
When switching between Windows and WSL debugging:
1. **Right-click your project** in Solution Explorer
2. **Select "Edit Project File"**
3. **Update the RuntimeIdentifier**:
```xml
<!-- For Windows debugging -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<!-- For WSL/Linux debugging -->
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
```
### 3. Enable WSL Debugging
For WSL debugging, ensure:
- **WSL2 is installed** and configured
- **Linux distribution** is set in the launch profile
- **Project targets Linux RID** for WSL debugging
## 🚀 Debugging Workflow
### ASP.NET-First Debugging (Default)
1. **Select "ASP.Net (unpackaged)"** profile in Visual Studio
2. **Press F5** to start debugging
3. **Set breakpoints** in your C# code
4. **Use Hot Reload** to edit ASP.NET code during runtime
5. **Stop debugging** when finished
### Electron Process Debugging
1. **Select "Electron (unpackaged)"** profile
2. **Press F5** to start debugging
3. **Attach to Electron process** if needed
4. **Debug Node.js and Electron APIs**
### Cross-Platform Debugging
1. **Set RuntimeIdentifier** to `linux-x64`
2. **Select "WSL"** profile
3. **Press F5** to debug in WSL
4. **Test Linux-specific behavior**
## 🔍 Debugging Tips
### Hot Reload
- **Works with ASP.NET-first debugging**
- **Edit Razor views, controllers, and pages**
- **See changes instantly** without restart
- **Preserves application state**
### Breakpoint Debugging
```csharp
// Set breakpoints here
public async Task<IActionResult> Index()
{
var data = await GetData(); // ← Breakpoint
return View(data);
}
```
### Process Management
- **ASP.NET-first mode** automatically manages Electron process lifecycle
- **Proper cleanup** on debugging session end
- **No manual process killing** required
## 🛠 Troubleshooting
### Common Issues
**"Electron process not found"**
- Ensure Node.js 22.x is installed
- Check that packages are restored (`dotnet restore`)
- Verify RuntimeIdentifier matches your target platform
**"WSL debugging fails"**
- Install and configure WSL2
- Ensure Linux distribution is properly set up
- Check that project targets correct RID
**"Hot Reload not working"**
- Use ASP.NET-first debugging profile
- Ensure ASPNETCORE_ENVIRONMENT=Development
- Check for compilation errors
## 🎨 Visual Debugging
*Placeholder for image showing Visual Studio debugging interface with Electron.NET*
The debugging interface provides familiar Visual Studio tools:
- **Locals and Watch windows** for variable inspection
- **Call Stack** for method call tracing
- **Immediate Window** for runtime evaluation
- **Hot Reload** indicator for edit-and-continue
## 🚀 Next Steps
- **[Startup Methods](Startup-Methods.md)** - Understanding different launch scenarios
- **[Package Building](Package-Building.md)** - Debug packaged applications
- **[Migration Guide](../Core/Migration-Guide.md)** - Moving from old debugging workflows
## 💡 Benefits
**Native Visual Studio Experience** - No complex setup or manual attachment
**Hot Reload Support** - Edit ASP.NET code during debugging
**Cross-Platform Debugging** - Debug Linux apps from Windows
**Multiple Debugging Modes** - Choose the right approach for your needs
**Process Lifecycle Management** - Automatic cleanup and proper termination

View File

@@ -1,83 +1,85 @@
# Package Building
ElectronNET.Core integrates with Visual Studio's publishing system to create distributable Electron packages using electron-builder. The process leverages .NET's build system while automatically generating the necessary Electron configuration files.
explain how to use VS publish to create package with electron-builder.
## 🎯 Publishing Overview
The folder publishing is not the same between ASP.Net and console ap.
The publishing process differs slightly between ASP.NET and console applications:
## For ASP.Net, these are working publishing profiles:
- **ASP.NET Apps** - Use folder publishing with SelfContained=true
- **Console Apps** - Use folder publishing with SelfContained=false
## 📋 Prerequisites
Before publishing, ensure you have:
- **Node.js 22.x** installed
- **RuntimeIdentifier** set correctly for your target platform
- **Project configured** for Release builds
## 🚀 Publishing Process
### Step 1: Configure Runtime Identifier
Set the target platform in your `.csproj` file:
```xml
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <!-- or linux-x64, osx-x64, etc. -->
</PropertyGroup>
```
### Step 2: Create Publish Profile
Add publish profiles to `Properties/PublishProfiles/`:
#### ASP.NET Application Profile (Windows)
```xml
<?xml version="1.0" encoding="utf-8"?>
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
<Project>
<PropertyGroup>
<DeleteExistingFiles>true</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<ProjectGuid>6ea447d9-343f-46b8-b456-66557bddbb9f</ProjectGuid>
<SelfContained>true</SelfContained>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
</PropertyGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
<Project>
<PropertyGroup>
<DeleteExistingFiles>true</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ProjectGuid>6ea447d9-343f-46b8-b456-66557bddbb9f</ProjectGuid>
<SelfContained>true</SelfContained>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
</PropertyGroup>
</Project>
## For a console app, these ones are working:
<?xml version="1.0" encoding="utf-8"?>
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>publish\Release\net8.0\linux-x64</PublishDir>
<PublishDir>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
</PropertyGroup>
</Project>
```
#### ASP.NET Application Profile (Linux)
```xml
<?xml version="1.0" encoding="utf-8"?>
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>publish\Release\net8.0\win-x64</PublishDir>
<PublishDir>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
</PropertyGroup>
</Project>
```
#### Console Application Profile (Windows)
```xml
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
@@ -85,4 +87,235 @@ The folder publishing is not the same between ASP.Net and console ap.
<PublishReadyToRun>false</PublishReadyToRun>
</PropertyGroup>
</Project>
```
#### Console Application Profile (Linux)
```xml
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
</PropertyGroup>
</Project>
```
### Step 3: Configure Electron Builder
ElectronNET.Core automatically generates `electron-builder.json` based on your project configuration. Key settings include:
```json
{
"productName": "My Electron App",
"appId": "com.mycompany.myapp",
"directories": {
"output": "release"
},
"files": [
"**/*",
"!**/*.pdb"
],
"win": {
"target": "nsis",
"icon": "assets/app.ico"
},
"linux": {
"target": "AppImage",
"icon": "assets/app.png"
}
}
```
### Step 4: Publish from Visual Studio
1. **Right-click your project** in Solution Explorer
2. **Select "Publish"**
3. **Choose "Folder"** as the publish target
4. **Select your publish profile** (Windows/Linux)
5. **Click "Publish"**
The publish process will:
- Build your .NET application
- Generate Electron configuration files
- Copy Electron runtime files
- Install npm dependencies
- Create electron-builder configuration
### Step 5: Build Final Package
After publishing, build the final package:
```bash
# Navigate to publish directory
cd publish\Release\net8.0\win-x64\
# Install dependencies and build
npm install
npx electron-builder
# Find your package in the 'release' folder
```
## 📁 Output Structure
After publishing, your folder structure will look like:
```
publish\Release\net8.0\win-x64\
├── MyElectronApp.exe # Your .NET application
├── .electron\ # Electron runtime files
│ ├── main.js
│ ├── package.json
│ └── node_modules\
├── wwwroot\ # (ASP.NET only) Web assets
├── electron-builder.json # Build configuration
└── release\ # Final packages (after electron-builder)
├── MyElectronApp-1.0.0.exe
└── MyElectronApp-1.0.0-setup.exe
```
## 🔧 Configuration Options
### Project Configuration
Configure Electron settings in your `.csproj`:
```xml
<PropertyGroup>
<ElectronNETCoreDescription>My Electron Application</ElectronNETCoreDescription>
<ElectronNETCoreDisplayName>MyApp</ElectronNETCoreDisplayName>
<ElectronNETCoreAuthorName>Your Company</ElectronNETCoreAuthorName>
<ElectronNETCoreVersion>1.0.0</ElectronNETCoreVersion>
</PropertyGroup>
```
### Electron Builder Configuration
Customize `electron-builder.json` for your needs:
```json
{
"productName": "MyApp",
"appId": "com.mycompany.myapp",
"copyright": "Copyright © 2024 My Company",
"win": {
"target": "nsis",
"icon": "assets/icon.ico",
"publisherName": "My Company"
},
"linux": {
"target": "AppImage",
"icon": "assets/icon.png",
"category": "Office"
}
}
```
## 🎯 Platform-Specific Settings
### Windows Configuration
```json
{
"win": {
"target": "nsis",
"icon": "assets/app.ico",
"verifyUpdateCodeSignature": false
}
}
```
### Linux Configuration
```json
{
"linux": {
"target": "AppImage",
"icon": "assets/app.png",
"category": "Development"
}
}
```
### macOS Configuration
```json
{
"mac": {
"target": "dmg",
"icon": "assets/app.icns",
"category": "public.app-category.developer-tools"
}
}
```
## 🚀 Advanced Publishing
### Cross-Platform Building
Build for multiple platforms from Windows using WSL:
1. **Set RuntimeIdentifier** to `linux-x64`
2. **Publish to folder** using Linux profile
3. **Copy to WSL** or build directly in WSL
### CI/CD Integration
For automated builds:
```bash
# Restore packages
dotnet restore
# Publish for specific platform
dotnet publish -c Release -r win-x64 --self-contained
# Build Electron package
cd publish\Release\net8.0\win-x64
npm install
npx electron-builder --publish=never
```
## 🛠 Troubleshooting
### Common Issues
**"electron-builder.json not found"**
- Ensure project is published first
- Check that RuntimeIdentifier is set
- Verify .NET build succeeded
**"npm install fails"**
- Ensure Node.js 22.x is installed
- Check internet connection for npm packages
- Verify no conflicting package versions
**"WSL publishing fails"**
- Ensure WSL2 is properly configured
- Check that Linux RID is set correctly
- Verify WSL can access Windows files
## 🎨 Publishing Workflow
*Placeholder for image showing Visual Studio publish dialog and electron-builder output*
## 🚀 Next Steps
- **[Startup Methods](Startup-Methods.md)** - Understanding different launch modes for packaged apps
- **[Debugging](Debugging.md)** - Debug packaged applications
- **[Migration Guide](../Core/Migration-Guide.md)** - Update existing projects for new publishing
## 💡 Benefits
**Native VS Integration** - Use familiar publish workflows
**Cross-Platform Building** - Build Linux packages from Windows
**Automatic Configuration** - No manual electron-builder setup
**Multiple Package Types** - NSIS, AppImage, DMG, etc.
**CI/CD Ready** - Easy integration with build pipelines

View File

@@ -1,17 +1,243 @@
# Startup Methods
// Explain the different startup modes
ElectronNET.Core supports multiple startup methods to handle different development and deployment scenarios. The framework automatically detects the appropriate mode based on command-line flags and environment.
- 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
## 🎯 Startup Scenarios
The framework supports **8 different launch scenarios** covering every combination of:
![Startup Modes](../images/startup_modes.png)
- **Packaged vs Unpackaged** deployment
- **Console vs ASP.NET** application types
- **Dotnet-first vs Electron-first** initialization
## 🚀 Command-Line Flags
### Unpackaged Debugging Modes
**`-unpackedelectron`** - Electron-first debugging
```bash
# Launch Electron first, which then starts .NET
node node_modules/electron/cli.js main.js -unpackedelectron
```
**`-unpackeddotnet`** - .NET-first debugging
```bash
# Launch .NET first, which then starts Electron
dotnet run -unpackeddotnet
```
### Packaged Deployment Modes
**`-dotnetpacked`** - .NET-first packaged execution
```bash
# Run packaged app with .NET starting first
MyApp.exe -dotnetpacked
```
**No flags** - Electron-first packaged execution (default)
```bash
# Run packaged app with Electron starting first
MyApp.exe
```
## 📋 Startup Method Details
### 1. Unpackaged + Electron-First (Development)
- **Use Case**: Debug Electron main process and Node.js code
- **Command**: `-unpackedelectron` flag
- **Process Flow**:
1. Electron starts first
2. Electron launches .NET process
3. .NET connects back to Electron
4. Application runs with Electron in control
### 2. Unpackaged + .NET-First (Development)
- **Use Case**: Debug ASP.NET/C# code with Hot Reload
- **Command**: `-unpackeddotnet` flag
- **Process Flow**:
1. .NET application starts first
2. .NET launches Electron process
3. Electron connects back to .NET
4. Application runs with .NET in control
### 3. Packaged + .NET-First (Production)
- **Use Case**: Deployed application with .NET controlling lifecycle
- **Command**: `-dotnetpacked` flag
- **Process Flow**:
1. .NET executable starts first
2. .NET launches Electron from packaged files
3. Electron loads from app.asar or extracted files
4. .NET maintains process control
### 4. Packaged + Electron-First (Production)
- **Use Case**: Traditional Electron app behavior
- **Command**: No special flags
- **Process Flow**:
1. Electron executable starts first
2. Electron launches .NET from packaged files
3. .NET runs from Electron's process context
4. Electron maintains UI control
## 🔧 Configuration Examples
### ASP.NET Application Startup
```csharp
// Program.cs
var builder = WebApplication.CreateBuilder(args);
// Configure for different startup modes
builder.WebHost.UseElectron(args, async () =>
{
var browserWindow = await Electron.WindowManager.CreateWindowAsync(
new BrowserWindowOptions { Show = false });
await browserWindow.WebContents.LoadURLAsync("https://localhost:7001");
browserWindow.OnReadyToShow += () => browserWindow.Show();
});
var app = builder.Build();
app.Run();
```
### Console Application Startup
```csharp
// Program.cs
public static async Task Main(string[] args)
{
var runtimeController = ElectronNetRuntime.RuntimeController;
await runtimeController.Start();
await runtimeController.WaitReadyTask;
await InitializeApplication();
await runtimeController.WaitStoppedTask;
}
```
## 🎨 Visual Process Flow
*Placeholder for image showing the 8 different startup mode flows*
The image above illustrates how each combination of deployment type, application type, and initialization order affects the process lifecycle.
## 🚀 Development Workflows
### Debugging Workflow
**ASP.NET-First Debugging** (Recommended)
```json
// launchSettings.json
{
"ASP.Net (unpackaged)": {
"commandName": "Project",
"commandLineArgs": "-unpackeddotnet"
}
}
```
**Electron-First Debugging**
```json
// launchSettings.json
{
"Electron (unpackaged)": {
"commandName": "Executable",
"executablePath": "node",
"commandLineArgs": "node_modules/electron/cli.js main.js -unpackedelectron"
}
}
```
### Production Deployment
**Dotnet-First Deployment**
```bash
# Build and package
dotnet publish -c Release -r win-x64
cd publish\Release\net8.0\win-x64
npm install
npx electron-builder
# Run with dotnet-first
MyApp.exe -dotnetpacked
```
**Electron-First Deployment** (Default)
```bash
# Run packaged application (no special flags needed)
MyApp.exe
```
## 🔍 Process Lifecycle Management
### Automatic Cleanup
ElectronNET.Core automatically manages process lifecycle:
- **Graceful shutdown** when main window is closed
- **Proper cleanup** of child processes
- **Error handling** for process failures
- **Cross-platform compatibility** for process management
### Manual Control
Access runtime controller for advanced scenarios:
```csharp
var runtime = ElectronNetRuntime.RuntimeController;
// Wait for Electron to be ready
await runtime.WaitReadyTask;
// Stop Electron runtime
await runtime.Stop();
await runtime.WaitStoppedTask;
```
## 🛠 Troubleshooting
### Common Startup Issues
**"Electron process not found"**
- Ensure Node.js 22.x is installed
- Check that .NET build succeeded
- Verify RuntimeIdentifier is set correctly
**"Port conflicts"**
- Use different ports for different startup modes
- Check that no other instances are running
- Verify firewall settings
**"Process won't terminate"**
- Use dotnet-first mode for better cleanup
- Check for unhandled exceptions
- Verify all windows are properly closed
## 💡 Best Practices
### Choose the Right Mode
- **Development**: Use .NET-first for C# debugging, Electron-first for Node.js debugging
- **Production**: Use .NET-first for better process control, Electron-first for traditional behavior
- **Cross-platform**: Use .NET-first for consistent behavior across platforms
### Environment Configuration
```xml
<!-- .csproj -->
<PropertyGroup>
<ElectronNETCoreEnvironment>Production</ElectronNETCoreEnvironment>
</PropertyGroup>
```
## 🚀 Next Steps
- **[Debugging](Debugging.md)** - Debug different startup modes
- **[Package Building](Package-Building.md)** - Package for different deployment scenarios
- **[Migration Guide](../Core/Migration-Guide.md)** - Update existing apps for new startup methods
## 🎯 Summary
The flexible startup system ensures ElectronNET.Core works optimally in every scenario while providing the control and debugging experience .NET developers expect. Choose the appropriate mode based on your development workflow and deployment requirements.