Quick start for .NET application

This guide shows how to start working with DotNetBrowser and embed it in a simple console application.

Environment:

  • Windows
  • Ubuntu 18.04+
  • Debian 10+
  • Fedora Linux 33+
  • openSUSE 15.2+
  • RedHat Enterprise Linux 7
  • macOS 10.15+

.NET Core 3.1, .NET 5 or .NET 6.

1. Create a .NET console application

Open the Terminal or Command Line prompt, navigate to the necessary directory and run the following command:

dotnet new console -o Example.Console

The project will be created in the folder Example.Console.

2. Configure EAP NuGet feed

Run below command:

dotnet nuget add source "https://pkgs.dev.azure.com/teamdev-products/66fbd081-377c-4af2-a64d-fee8ca740ed4/_packaging/dotnetbrowser-eaps/nuget/v3/index.json" --name "DotNetBrowser EAP NuGet feed"

3. Add DotNetBrowser package

Change directory to Example.Console and add the required package for your OS:

Windows:

dotnet add package DotNetBrowser --prerelease

Linux:

dotnet add package DotNetBrowser.Linux-x64 --prerelease

macOS:

dotnet add package DotNetBrowser.macOS-x64 --prerelease

Cross Platform:

dotnet add package DotNetBrowser.CrossPlatform --prerelease

.NET Core 3.1 does not support --prerelease command parameter. Instead, it is required to specify the exact package version. For example:
dotnet add package DotNetBrowser.macOS-x64 -v "2.16.0-b2840-eap"

To find the latest available EAP version, click here.

4. Change source code

Insert the following code using any text editor into the Program.cs file:

using System;
using DotNetBrowser.Browser;
using DotNetBrowser.Engine;

namespace Example.Console
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            using (IEngine engine = EngineFactory.Create())
            {
                IBrowser browser = engine.CreateBrowser();
                browser.Navigation.LoadUrl("https://html5test.com/").Wait();
                System.Console.WriteLine($"Web page title: {browser.Title}");
            }

            System.Console.WriteLine("Press any key to terminate...");
            System.Console.ReadKey();
        }
    }
}
Imports System
Imports DotNetBrowser.Browser
Imports DotNetBrowser.Engine

Namespace Example.Console
	Friend Class Program
		Public Shared Sub Main(args() As String)
			Using engine As IEngine = EngineFactory.Create()
				Dim browser As IBrowser = engine.CreateBrowser()
				browser.Navigation.LoadUrl("https://html5test.com/").Wait()
				System.Console.WriteLine($"Web page title: {browser.Title}")
			End Using

			System.Console.WriteLine("Press any key to terminate...")
			System.Console.ReadKey()
		End Sub
	End Class
End Namespace

5. Get trial license

To get a free 30-day trial license, fill in the web form and click the GET MY FREE TRIAL button. You will receive an email with the license key.

6. Add a license

To embed the license key into your project, copy the license key string from the email and insert it as shown below:

IEngine engine = EngineFactory.Create(new EngineOptions.Builder
{
    LicenseKey = "your_license_key"
}.Build());

For more information on license installation, refer to this article.

7. Run the application

To launch application, use:

dotnet run
Go Top