I am trying to create an electron desktop app with angular as frontend and .net as backend. I created a sample angular project in .netcore 2.0 from VS 2017 and followed the steps mentioned here
I'm having issues with dotnet electronize init
command. It's giving below error :
No executable found matching command "dotnet-electronize"
Can someone please let me know if I'm missing anything. Also if there is any boilerplate code which I can refer to would be really helpful.
Now, we must install Electron in our Angular app. Open a new terminal and run the below command. Even after installing, Electron will be unaware of the Angular app. So, it should be linked with the Angular app in order to work. Create a script file named as main.js and copy the below code in it.
It is a popular platform for building cross-platform desktop apps for Windows, Linux and macOS with JavaScript, HTML, and CSS.It is essentially a web application that is self-contained as a desktop application. In this guide, we will look at how to create an Electron application with the Angular framework using TypeScript.
In this article, we learned about how to use Angular applications as a desktop application using Electron.
If you look in your project’s folder, you’ll see that Angular CLI builds your app in the dist/electron-angular-demo folder instead of just the dist folder. In our main.js file, we are telling Electron to look for the index.html file in the dist folder without a subfolder: __dirname refers to the current folder from which we’re running Electron.
I was using powershell which has some unexpected behavior.Check here for more details.
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() .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
Got it from here: https://github.com/rajeshsuramalla/AngularWithDotNetCoreElectronNET
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With