2025-10-15 12:50:31 +02:00
2025-10-14 09:52:44 +02:00
# ASP.NET Core Setup
2025-10-15 12:50:31 +02:00
2025-10-14 09:52:44 +02:00
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.
2025-10-15 12:50:31 +02:00
2025-10-14 09:52:44 +02:00
## 🛠 System Requirements
2025-10-15 12:50:31 +02:00
2025-10-15 16:06:09 +02:00
See [System Requirements ](../GettingStarted/System-Requirements.md ).
2025-10-15 12:50:31 +02:00
2025-10-14 09:52:44 +02:00
## 🚀 Quick Start
2025-10-15 12:50:31 +02:00
2025-10-14 09:52:44 +02:00
### 1. Create ASP.NET Core Project
2025-10-15 12:50:31 +02:00
2025-10-15 23:04:37 +02:00
#### Visual Studio
Create a new ASP.NET Core Web App in Visual Studio by selecting **New Project ** and choosing one of the ASP.NET Core project templates.
#### From the command line
2025-10-14 09:52:44 +02:00
```bash
dotnet new webapp -n MyElectronWebApp
cd MyElectronWebApp
2025-10-15 12:50:31 +02:00
```
2025-10-14 09:52:44 +02:00
### 2. Install NuGet Packages
2025-10-15 12:50:31 +02:00
2025-10-15 23:04:37 +02:00
#### Visual Studio
Right-click the solution and select **Manage Nuget Packages ** .
Finr and install `ElectronNET.Core` as well as `ElectronNET.Core.AspNet` .
#### From the command line
2025-10-14 09:52:44 +02:00
```powershell
2025-10-15 23:04:37 +02:00
dotnet add package ElectronNET.Core
dotnet add package ElectronNET.Core.AspNet
2025-10-14 09:52:44 +02:00
```
2025-10-15 16:06:09 +02:00
> [!Note]
2025-10-15 23:04:37 +02:00
> The API package is automatically included as a dependency of `ElectronNET.Core`.
2025-10-14 09:52:44 +02:00
2025-10-15 12:50:31 +02:00
2025-10-14 09:52:44 +02:00
### 3. Configure Program.cs
2025-10-15 12:50:31 +02:00
2025-10-14 09:52:44 +02:00
Update your `Program.cs` to enable Electron.NET:
2025-10-15 12:50:31 +02:00
2025-10-14 09:52:44 +02:00
```csharp
2025-10-15 12:50:31 +02:00
using ElectronNET.API;
using ElectronNET.API.Entities;
2025-10-15 16:06:09 +02:00
public class Program
2025-10-14 09:52:44 +02:00
{
2025-10-15 16:06:09 +02:00
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
2025-10-14 09:52:44 +02:00
2025-10-15 16:06:09 +02:00
builder.Services.AddRazorPages();
2025-10-14 09:52:44 +02:00
2025-10-15 16:06:09 +02:00
// Add this line to enable Electron.NET:
builder.UseElectron(args, ElectronAppReady);
2025-10-14 09:52:44 +02:00
2025-10-15 16:06:09 +02:00
var app = builder.Build();
2025-10-14 09:52:44 +02:00
2025-10-15 16:06:09 +02:00
if (!app.Environment.IsDevelopment())
2025-10-14 09:52:44 +02:00
{
2025-10-15 16:06:09 +02:00
app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();
2025-10-14 09:52:44 +02:00
2025-10-15 16:06:09 +02:00
app.UseRouting();
2025-10-14 09:52:44 +02:00
2025-10-15 16:06:09 +02:00
app.UseAuthorization();
2025-10-14 09:52:44 +02:00
2025-10-15 16:06:09 +02:00
app.MapRazorPages();
2025-10-14 09:52:44 +02:00
2025-10-15 16:06:09 +02:00
app.Run();
}
2025-10-14 09:52:44 +02:00
2025-10-15 16:06:09 +02:00
public static async Task ElectronAppReady()
{
var browserWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { Show = false });
2025-10-14 09:52:44 +02:00
2025-10-15 16:06:09 +02:00
browserWindow.OnReadyToShow += () => browserWindow.Show();
}
2025-10-14 09:52:44 +02:00
}
```
2025-10-15 12:50:31 +02:00
2025-10-15 16:06:09 +02:00
#### ASP.NET Port
2025-10-14 09:52:44 +02:00
2025-10-15 16:06:09 +02:00
If you want to launch a specific URL, you can retrieve the actual ASP.NET port from the new `ElectronNetRuntime` static class, for example:
2025-10-14 09:52:44 +02:00
```csharp
2025-10-15 16:06:09 +02:00
await browserWindow.WebContents
.LoadURLAsync($"http://localhost:{ElectronNetRuntime.AspNetWebPort}/mypage.html");
2025-10-14 09:52:44 +02:00
```
2025-10-15 16:06:09 +02:00
### 4. Alternative: IWebHostBuilder Setup
2025-10-14 09:52:44 +02:00
2025-10-15 16:06:09 +02:00
For projects using the traditional `Startup.cs` pattern, please see "Traditional ASP.NET Core" in the [Migration Guide ](../Core/Migration-Guide.md ).
2025-10-14 09:52:44 +02:00
2025-10-15 22:12:29 +02:00
### 5. Dependency Injection
ElectronNET.API can be added to your DI container within the `Startup` class. All of the modules available in Electron will be added as Singletons.
```csharp
using ElectronNET.API;
public void ConfigureServices(IServiceCollection services)
{
services.AddElectron();
}
```
2025-10-14 09:52:44 +02:00
## 🚀 Next Steps
2025-10-15 22:12:29 +02:00
- **[Debugging ](../Using/Debugging.md )** - Learn about ASP.NET debugging features
- **[Package Building ](../Using/Package-Building.md )** - Create distributable packages
- **[Startup Methods ](../Using/Startup-Methods.md )** - Understanding launch scenarios
2025-10-14 09:52:44 +02:00
## 💡 Benefits of ASP.NET + Electron
2025-10-15 16:06:09 +02:00
✅ **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