C#:在AnyCPU模式下使用CefSharp
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------
本篇博客讲述如何在AnyCPU模式下使用CefSharp
因为在某些情况下,不得不用AnyCPU,但是CefSharp支持的是86和64位俩种模式,所以在我查阅了很多国内外的资料下,总结出来的一些精华
参考地址:
https://ourcodeworld.com/articles/read/173/how-to-use-cefsharp-chromium-embedded-framework-csharp-in-a-winforms-application
https://github.com/cefsharp/CefSharp/issues/1714
https://github.com/cefsharp/CefSharp.MinimalExample/blob/demo/anycpu/CefSharp.MinimalExample.Wpf/App.xaml.cs
三篇结合就可以实现在AnyCPU下使用CefSharp
简单步骤记录
第一篇博客取其第二个,更改配置的那一块,这块不改,下面的没用,项目起不起来
简述一下:
1.修改为首选32位,
2.在你项目名.csproj文件下,加一段
<CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport>
位置如下:
3.在App.config下加一端
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="x86"/>
</assemblyBinding>
</runtime>
位置如下:
第二篇博客取的精髓在这块,我给放过来
public partial class App : Application
{
public App()
{
//Add Custom assembly resolver
AppDomain.CurrentDomain.AssemblyResolve += Resolver; //Any CefSharp references have to be in another method with NonInlining
// attribute so the assembly rolver has time to do it's thing.
InitializeCefSharp();
} [MethodImpl(MethodImplOptions.NoInlining)]
private static void InitializeCefSharp()
{
var settings = new CefSettings(); // Set BrowserSubProcessPath based on app bitness at runtime
settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
Environment.Is64BitProcess ? "x64" : "x86",
"CefSharp.BrowserSubprocess.exe"); // Make sure you set performDependencyCheck false
Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);
} // Will attempt to load missing assembly from either x86 or x64 subdir
// Required by CefSharp to load the unmanaged dependencies when running using AnyCPU
private static Assembly Resolver(object sender, ResolveEventArgs args)
{
if (args.Name.StartsWith("CefSharp"))
{
string assemblyName = args.Name.Split(new[] { ',' }, )[] + ".dll";
string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
Environment.Is64BitProcess ? "x64" : "x86",
assemblyName); return File.Exists(archSpecificPath)
? Assembly.LoadFile(archSpecificPath)
: null;
} return null;
}
}
第三篇博客 就是告诉你using指令怎么引,以及详细的写法,要用的话,还是用第二篇博客的这段代码
using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Windows; namespace CefSharp.MinimalExample.Wpf
{
public partial class App : Application
{
public App()
{
//Add Custom assembly resolver
AppDomain.CurrentDomain.AssemblyResolve += Resolver; //Any CefSharp references have to be in another method with NonInlining
// attribute so the assembly rolver has time to do it's thing.
InitializeCefSharp();
} [MethodImpl(MethodImplOptions.NoInlining)]
private static void InitializeCefSharp()
{
//Perform dependency check to make sure all relevant resources are in our output directory.
var settings = new CefSettings();
settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
Environment.Is64BitProcess ? "x64" : "x86",
"CefSharp.BrowserSubprocess.exe"); Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler:null);
} // Will attempt to load missing assembly from either x86 or x64 subdir
// Required by CefSharp to load the unmanaged dependencies when running using AnyCPU
private static Assembly Resolver(object sender, ResolveEventArgs args)
{
if (args.Name.StartsWith("CefSharp"))
{
string assemblyName = args.Name.Split(new[] { ',' }, )[] + ".dll";
string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
Environment.Is64BitProcess ? "x64" : "x86",
assemblyName); return File.Exists(archSpecificPath)
? Assembly.LoadFile(archSpecificPath)
: null;
} return null;
}
}
}
三套组合拳打完,CefSharp就可以在AnyCPU模式下使用了
C#:在AnyCPU模式下使用CefSharp的更多相关文章
- 基于 Vue.js 之 iView UI 框架非工程化实践记要 使用 Newtonsoft.Json 操作 JSON 字符串 基于.net core实现项目自动编译、并生成nuget包 webpack + vue 在dev和production模式下的小小区别 这样入门asp.net core 之 静态文件 这样入门asp.net core,如何
基于 Vue.js 之 iView UI 框架非工程化实践记要 像我们平日里做惯了 Java 或者 .NET 这种后端程序员,对于前端的认识还常常停留在 jQuery 时代,包括其插件在需要时就引 ...
- 微软Azure 经典模式下创建内部负载均衡(ILB)
微软Azure 经典模式下创建内部负载均衡(ILB) 使用之前一定要注意自己的Azure的模式,老版的为cloud service模式,新版为ARM模式(资源组模式) 本文适用于cloud servi ...
- 苹果手机Safari无痕浏览模式下系统登录成功但是页面不跳转
昨天下午,测试提了一个bug,问题是:在苹果手机Safari无痕浏览模式下系统登录成功但是页面不跳转. 思前想后找了半天没思路,后来经过同事的点拨,说可能是禁用了cookie之类的,反正我也没思路就顺 ...
- win10 下visual studio 2015 在调试模式下不能跟踪源文件
win10 下visual studio 2015 在调试模式下不能跟踪源文件,只要一调试就会关闭(隐藏)打开的文档,非常不方便.经过一番折腾,发现是配置的问题. 如果安装多个版本的VS,请删除对应版 ...
- 转:IE兼容模式下 SCRIPT1028: 缺少标识符、字符串或数字
IE兼容模式下 SCRIPT1028: 缺少标识符.字符串或数字例如下面一段代码 var a = { x: 1, y: 2,};alert(a.x);如果在IE的兼容性视图(IE7文档模式 ...
- 【配置】检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(非简单设置为【经典】模式)。
× 检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(非简单设置为[经典]模式). 我们将ASP.NET程序从IIS6移植到IIS7,可能运行提示以下错误: HTTP 错误 5 ...
- Linux学习之CentOS(二十二)--单用户模式下修改Root用户的密码
在上一篇随笔里面详细讲解了Linux系统的启动过程 (Linux学习之CentOS(二十一)--Linux系统启动详解),我们知道Linux系统的启动级别一共有6种级别,通过 /etc/inittab ...
- MVC开发模式下的用户角色权限控制
前提: MVC开发模式 大概思想: 1.在MVC开发模式下,每个功能都对应着不同的控制器或操作方法名(如修改密码功能可能对应着User/changepd),把每个功能对应的控制器名和操作方法名存到数据 ...
- TreeView 使用方法:(在View.Details模式下)
1.建立TreeView的標題 2.建立TreeView的Item 3.在TreeView的Item中的建立SubItem 如果將各部 ...
随机推荐
- 【[SCOI2009]迷路】
大水题一遍 过掉比较繁琐的拆点还是非常开心的 发现每一条边的边权可能不是\(1\),但是边权的范围非常小,同时点数也非常小,只有\(n<=10\),所以我们可以将一个点拆成九个点,之后随便一连边 ...
- [转]百度地图API详解之地图坐标系统
博客原文地址:http://www.jiazhengblog.com/blog/2011/07/02/289/ 我们都知道地球是圆的,电脑显示器是平的,要想让位于球面的形状显示在平面的显示器上就必然需 ...
- 超低功耗WiFi :ESP8089
ESP8089是一个完整且自成体系的Wi-Fi网络解决方案.当ESP8089作为Wi-Fi适配器 时,可以将其与任何微控制器配合,无线网络接入可以实现在配合的任何一种处理器上p 网络连接只需通过SPI ...
- 框架 Hibernate
Hibernate 在test01右键新建其他找到hibernate文件夹下的Hibernate Configuration File(cfg.xml) <?xml version=" ...
- 关于如何解决bootstrap table 列 切换 刷新 高度不一样
在使用bootstrap table时候,碰到bootstrap table 列 切换 刷新 高度不一样的问题,如图所示: 解决这个问题很简单,在你的页头加一句<!DOCTYPE html> ...
- 前端基础-HTML的的标签详解
阅读目录 一.head内常用标签 二. HTML语义化 三. 字符实体 四. h系列标签 五. p标签 六. img标签 七. a标签 八. 列表标签 九. table标签 十. form标签 一. ...
- Unity-iPhone has Conflicting Provisioning Settings
Select the top level node called Unity-iPhone in the left tree view (the one with the blue item). Se ...
- [译]C语言实现一个简易的Hash table(3)
上一章,我们讲了hash表的数据结构,并简单实现了hash表的初始化与删除操作,这一章我们会讲解Hash函数和实现算法,并手动实现一个Hash函数. Hash函数 本教程中我们实现的Hash函数将会实 ...
- vue相关理论知识
es6常用语法简介 es是js的规范标准 let 特点: 1.有全局和函数作用域,以及块级作用域(用{}表示块级作用域范围) 2.不会存在变量提升 3.变量不能重复声明 const 特点: 1.有块级 ...
- PHP 审计
1.get 和post 上传数组,数组的sha1值相等 通过阅读代码,我们发现要想得到flag就要达到下面三个条件: 使 uname的sha1值 与 passwd的sha1的值 相等 但是同 ...