- Checkout AppVeyor Aritfacts: Contains the WebApp sample built for Windows & Linux!
Build cross platform desktop apps with .NET Core 2.0 and ASP.NET NET Core.
Electron.NET is a wrapper around a "normal" Electron application with an embedded ASP.NET Core application. Via our Electron.NET IPC bridge we can invoke Electron APIs from .NET.
The CLI extensions hosts our toolset to build and start Electron.NET applications.
Well... there are lots of different approaches how to get a X-plat desktop app running. We thought it would be nice for .NET devs to use the ASP.NET Core environment and just embed it inside a pretty robust X-plat enviroment called Electron. Porting Electron to .NET is not a goal of this project, at least we don't have any clue how to do it. We just combine ASP.NET Core & Electron.
The current Electron.NET CLI builds Windows/macOS/Linux binaries. Our API uses .NET Core 2.0, so our minimum base OS is the same as .NET Core 2.
To activate and communicate with the "native" (sort of native...) Electron API include the ElectronNET.API NuGet package in your ASP.NET Core app.
PM> Install-Package ElectronNET.API
You start Electron.NET up with an UseElectron
WebHostBuilder-Extension.
public static IWebHost BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.UseElectron(args)
.UseStartup<Startup>()
.Build();
}
Open the Electron Window in the Startup.cs file:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
// Open the Electron-Window here
Task.Run(async () => await Electron.WindowManager.CreateWindowAsync());
}
Please note: Currently it is important to use ASP.NET Core with MVC. If you are working with the dotnet CLI, use
dotnet new mvc
For the tooling you will need your dotnet-electronize package ElectronNET.CLI NuGet package. This package must be referenced in the .csproj like this:
<ItemGroup>
<DotNetCliToolReference Include="ElectronNET.CLI" Version="0.0.9" />
</ItemGroup>
Be aware of the version: The current version of the CLI is 0.0.9.
After you edited the .csproj-file, you need to restore your NuGet packages within your Project. Run the follwoing command in your ASP.NET Core folder:
dotnet restore
-
Make sure you have node.js v8.6.0 and on macOS/Linux the electron-packager installed!
sudo npm install electron-packager --global
At the first time, you need an Electron.NET project initialization. Type the following command in your ASP.NET Core folder:
dotnet electronize init
- Now a electronnet.manifest.json should appear in your ASP.NET Core project
- Now run the following:
dotnet electronize start
Only the first electronize start is slow. The next will go on faster.
Start your Electron.NET application with the Electron.NET CLI command. In Visual Studio attach to your running application instance. Go in the Debug Menu and click on Attach to Process.... Sort by your projectname on the right and select it on the list.
A complete documentation will follow. Until then take a look in the source code of the sample application:
Electron.NET API Demos
In this YouTube video, we show you how you can create a new project, use the Electron.NET API, debug a application and build an executable desktop app for Windows: Electron.NET - Getting Started
Here you need the Electron.NET CLI too. Type following command in your ASP.NET Core folder:
dotnet electronize build /target win
There are additional platforms available:
dotnet electronize build /target win
dotnet electronize build /target osx
dotnet electronize build /target linux
Those three "default" targets will produce x64 packages for those platforms.
For certain NuGet packages or certain scenarios you may want to build a pure x86 application. To support those things you can define the desired .NET Core runtime, the electron platform and electron architecture like this:
dotnet electronize build build /target custom win7-x86;win32 /electron-arch ia32
The end result should be an electron app under your /bin/desktop folder.
There is a React/Typescript/MobX starter kit at https://github.com/yoDon/Electron.NET-React-Typescript-MobX
macOS builds can't be created on Windows machines because they require symlinks that aren't supported on Windows (per this Electron issue). macOS builds can be produced on either Linux or macOS machines.
This repository consists of the main parts (API & CLI) and it's own "playground" ASP.NET Core application. Both main parts produce local NuGet packages, that are versioned with 1.0.0. The first thing you will need is to run one of the buildAll scripts (.cmd for Windows, the other for macOS/Linux).
If you look for pure demo projects checkout the other repositories.
The problem working with this repository is, that NuGet has a pretty aggressive cache, see here for further information.
Feel free to submit a pull request if you find any bugs (to see a list of active issues, visit the Issues section. Please make sure all commits are properly documented.
- Gregor Biswanger - (Microsoft MVP, Intel Black Belt and Intel Software Innovator) is a freelance lecturer, consultant, trainer, author and speaker. He is a consultant for large and medium-sized companies, organizations and agencies for software architecture, web- and cross-platform development. You can find Gregor often on the road attending or speaking at international conferences. - Cross-Platform-Blog - Twitter @BFreakout
- Robert Muehsig - Software Developer - from Dresden, Germany, now living & working in Switzerland. Microsoft MVP & Web Geek. - codeinside Blog - Twitter @robert0muehsig
See also the list of contributors who participated in this project.
MIT-licensed
Enjoy!