.Net Core 3.1 内嵌浏览器内核开发应用(ChromelyApp)
电脑版发表于:2020/12/23 10:36
安装nuget包Chromely
新建.Net Core 应用程序 控制台 web的都行 控制台需要格外导入中间件管道的nuget 会比较麻烦 建议新建.Net Core Web的空应用程序
launchBrowser 设置 false 不然会打开浏览器
Program.cs
AppBuilder .Create() .UseApp<DemoApp>() .Build() .Run(args);//生成ChromelyAPP 构建器 再运行
public class DemoApp : ChromelyBasicApp
{
public override void ConfigureServices(ServiceCollection services)
{
base.ConfigureServices(services);
services.AddLogging(configure => configure.AddConsole());
services.AddLogging(configure => configure.AddFile("Logs/serilog-{Date}.txt"));
//AppManager.GetInstance().Start();
//CreateHostBuilder(args).Build().Run();
var config = DefaultConfiguration.CreateForRuntimePlatform();
//config.WindowOptions.Fullscreen = true; //定义窗口是否全屏,调试时关闭改功能
config.WindowOptions.Title = "Title"; //定义窗口标题
//config.WindowOptions.Size = new WindowSize(1024,768); //设置窗口打开的起始大小
config.StartUrl = "local://html/container.html";
RegisterControllerAssembly(services, typeof(DemoApp).Assembly);
}
}ConfigureServices 就是 普通.Net Core 应用程序的服务配置
运行结果:
编译平台设置在应用程序的.csproj里
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>//linux-64 位 <!--<RuntimeIdentifier>win-x64</RuntimeIdentifier>-->// windows-64位 <!--<RuntimeIdentifier>osx-x64</RuntimeIdentifier>-->// mac -64
