Angular SPA with Dotnet Core and ElectronNet API
-
Open VS 2017 with Administrator mode
-
Create Asp.Net core Web Application with Angular template
-
Install the ElectronNET.CLI using following command "dotnet tool install ElectronNET.CLI -g"
-
Goto project folder and open cmd
-
Execute the following command "electronize init", it will create electron-manifest.json file in project folder
-
Right click on dependencies, goto Nuget package manager and install ElectronNET.API
-
Add ElectronBootstrap() method in Startup.cs
public async void ElectronBootstrap() { BrowserWindowOptions options = new BrowserWindowOptions { Show = false }; BrowserWindow mainWindow = await Electron.WindowManager.CreateWindowAsync(); mainWindow.OnReadyToShow += () => { mainWindow.Show(); }; mainWindow.SetTitle("App Name here"); MenuItem[] menu = new MenuItem[] { new MenuItem { Label = "File", Submenu=new MenuItem[] { new MenuItem { Label ="Exit", Click =()=>{Electron.App.Exit();} } } }, new MenuItem { Label = "Info", Click = async ()=> { await Electron.Dialog.ShowMessageBoxAsync("Welcome to App"); } } }; Electron.Menu.SetApplicationMenu(menu); }
-
Call that method from Configure() in Startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { ElectronBootstrap(); }
-
Add UseElectron(args) in Program.cs
public static IWebHostBuilder CreateWebHostBuilder(string[] args) { return WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseElectron(args); }
-
Build the project
-
Goto project folder, open cmd and execute the following command "electronize start", it will open the desktop application. First time it will take time.
-
Production build for windows: electronize build /target win
Prerequisites
- Dotnet core SDK 3.1
- Node js
- Angular
- ElectronNET.CLI 9.31.2