Skip to content
mattkol edited this page Jul 11, 2021 · 2 revisions

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.

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 Nuget Install-Package EdgeSharp -Version 0.9.0 Win32
EdgeSharp.WinForms Nuget Install-Package EdgeSharp.WinForms -Version 0.9.0 WinForm
EdgeSharp.Wpf Nuget 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
  1. 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).

  1. 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);
        }
    }
}
  1. 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
        }
    }
}
  1. 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";
        }
    }
}

SimpleEdgeSharp.zip

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)