-
Notifications
You must be signed in to change notification settings - Fork 30
Home
- Important
- Prerequisites
- Create a blank Project
- Configuration Manager
- Installing NuGet packages
- Setting up Required Project files
- Run Application
- Remove Console Window
Some notes before starting off.
- Visual Studio 2019 or Visual Studio Code is preferred but any editor can be used.
- With EdgeSharp you can create x64/x86 applications. The guide here is for x64 but applies to x86 too.
- While this article doesn't cover .NET Framework development, the project setup is fairly the same.
Before running EdgeSharp, ensure that WebView2 Runtime is installed.
-
If the Evergreen WebView2 Runtime is preferred, all that is required is to ensure that the Win32 SDK Version, WinForm SDK Version or Wpf SDK Version matches the installed runtime version. Use Release Notes to match SDK to Runtime Version.
-
For other distribution/installation options please see - https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution
-
If non Evergreen WebView2 Runtime option is chosen, then the developer need to ensure that the runtime location is properly configured - WebView2CreationOptions.
To create a new project, you will need to create a .NET 5 Console Project
If .NET Core is not installed (for ex. running an older version of Visual Studio) you can acquire it from the Visual Studio Installer or you can downloaded it from https://dotnet.microsoft.com/download/dotnet/5.0).
To make sure that Visual Studio builds the application for 64-bit, we will need to define this in the Configuration Manager
Note: This guide is for EdgeSharp W32, please see WinForm Sample or WPF Sample for WinForm and WPF.
Package | Version | Package Manager | Type |
---|---|---|---|
EdgeSharp | Install-Package EdgeSharp -Version 0.9.0 |
Win32 |
|
EdgeSharp.WinForms | Install-Package EdgeSharp.WinForms -Version 0.9.0 |
WinForm |
|
EdgeSharp.Wpf | Install-Package EdgeSharp.Wpf -Version 0.9.0 |
WPF |
Or install through the NuGet Package Manager GUI
app/
index.html
SampleEdgeSharpConfig.cs
SampleEdgeSharpApp.cs
Program.cs
- Create a folder called app and in it a html file index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>EdgeSharp</title>
</head>
<body>
Hello World!
</body>
</html>
Make sure that the index.html file has Copy to Output Directory set to Copy Always. You can check this through the file's Properties Window (Right-click on the file and choose Properties).
- Next open Program.cs, and replace the default code with the snippet below.
using EdgeSharp.Core;
namespace SimpleEdgeSharp
{
class Program
{
static void Main(string[] args)
{
// basic example of the application builder
AppBuilder
.Create()
.UseConfig<SampleEdgeSharpConfig>()
.UseApp<SampleEdgeSharpApp>()
.Build()
.Run(args);
}
}
}
- And create the SampleEdgeSharpApp class.
using EdgeSharp;
using System;
namespace SimpleEdgeSharp
{
class DemoEdgeSharpApp : EdgeSharpBasicApp
{
public override void ConfigureServices(IServiceCollection services)
{
base.ConfigureServices(services);
// other service configuration can be placed here
}
}
}
-
And create the SampleEdgeSharpConfig class.
Note: Adding a custom Configuration class is optional. If a new start url is not set, bing.com will be launched by default.
using EdgeSharp.Core.Defaults;
using EdgeSharp.Core.Infrastructure;
using System;
namespace SimpleEdgeSharp
{
class SampleEdgeSharpConfig: Configuration
{
public SampleEdgeSharpConfig() : base()
{
// var localResource = new UrlScheme("http", "app", null, UrlSchemeType.ResourceRequest);
var hostToFolderscheme = new UrlScheme("http", "app", "app", UrlSchemeType.HostToFolder);
// UrlSchemes.Add(localResource);
UrlSchemes.Add(hostToFolderscheme);
StartUrl = "http://app/index.html";
}
}
}
You are now ready to build/debug the demo application.
You can remove the console window by changing the Output type of the project from Console Application to Windows Application (Right-click on the project and choose Properties)
EdgeSharp
Getting Started
Resource handling - How files are loaded
Inter-process Communication (IPC)
- Introduction
- AddHostObjectToScript
- PostWebMessage
- Ajax XHR
- Action Controllers
- Creating & Registering Host Objects
- Creating & Registering PostWebMessage Script Promise
- Registering Custom Request Scheme Handlers
Customizing and Extending EdgeSharp
EdgeSharp Samples
Debugging