I have the following Electron.NET app:
using System.Reflection;
using ElectronNET.API;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseElectron(args);
builder.Services.AddElectron();
builder.Configuration.AddJsonFile(Path.Combine(Assembly.GetExecutingAssembly().Location, "appsettings.json"));
WebApplication app = builder.Build();
await app.StartAsync();
BrowserWindow browserWindow = await Electron.WindowManager.CreateWindowAsync(app.Configuration["Url"]);
browserWindow.SetMenuBarVisibility(false);
browserWindow.Maximize();
app.WaitForShutdown();
Among other settings, electron.manifest.json
contains:
"win": {
"target": "portable"
}
Now I do the following:
- Bundle the app via
electronize build /target win
. - Copy the bundled app into
C:temp
. - Create the file
appsettings.json
with the following content:
{
"Url": "https://www.google.com"
}
- Run the app.
The settings file C:tempappsettings.json
will not be picked up by the app as Assembly.GetExecutingAssembly().Location
points to a temporary directory in which the Electron.NET app is extracted.
How can I retrieve the path from where a portable Electron.NET app starts originally (i.e. C:temp
)?