------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------

本篇博客讲述如何在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文件下,加一段

  1. <CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport>

    位置如下:

    

  3.在App.config下加一端

  1. <runtime>
  2. <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  3. <probing privatePath="x86"/>
  4. </assemblyBinding>
  5. </runtime>

    位置如下:

    

第二篇博客取的精髓在这块,我给放过来

  1. public partial class App : Application
  2. {
  3. public App()
  4. {
  5. //Add Custom assembly resolver
  6. AppDomain.CurrentDomain.AssemblyResolve += Resolver;
  7.  
  8. //Any CefSharp references have to be in another method with NonInlining
  9. // attribute so the assembly rolver has time to do it's thing.
  10. InitializeCefSharp();
  11. }
  12.  
  13. [MethodImpl(MethodImplOptions.NoInlining)]
  14. private static void InitializeCefSharp()
  15. {
  16. var settings = new CefSettings();
  17.  
  18. // Set BrowserSubProcessPath based on app bitness at runtime
  19. settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
  20. Environment.Is64BitProcess ? "x64" : "x86",
  21. "CefSharp.BrowserSubprocess.exe");
  22.  
  23. // Make sure you set performDependencyCheck false
  24. Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);
  25. }
  26.  
  27. // Will attempt to load missing assembly from either x86 or x64 subdir
  28. // Required by CefSharp to load the unmanaged dependencies when running using AnyCPU
  29. private static Assembly Resolver(object sender, ResolveEventArgs args)
  30. {
  31. if (args.Name.StartsWith("CefSharp"))
  32. {
  33. string assemblyName = args.Name.Split(new[] { ',' }, )[] + ".dll";
  34. string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
  35. Environment.Is64BitProcess ? "x64" : "x86",
  36. assemblyName);
  37.  
  38. return File.Exists(archSpecificPath)
  39. ? Assembly.LoadFile(archSpecificPath)
  40. : null;
  41. }
  42.  
  43. return null;
  44. }
  45. }

第三篇博客 就是告诉你using指令怎么引,以及详细的写法,要用的话,还是用第二篇博客的这段代码

  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. using System.Runtime.CompilerServices;
  5. using System.Windows;
  6.  
  7. namespace CefSharp.MinimalExample.Wpf
  8. {
  9. public partial class App : Application
  10. {
  11. public App()
  12. {
  13. //Add Custom assembly resolver
  14. AppDomain.CurrentDomain.AssemblyResolve += Resolver;
  15.  
  16. //Any CefSharp references have to be in another method with NonInlining
  17. // attribute so the assembly rolver has time to do it's thing.
  18. InitializeCefSharp();
  19. }
  20.  
  21. [MethodImpl(MethodImplOptions.NoInlining)]
  22. private static void InitializeCefSharp()
  23. {
  24. //Perform dependency check to make sure all relevant resources are in our output directory.
  25. var settings = new CefSettings();
  26. settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
  27. Environment.Is64BitProcess ? "x64" : "x86",
  28. "CefSharp.BrowserSubprocess.exe");
  29.  
  30. Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler:null);
  31. }
  32.  
  33. // Will attempt to load missing assembly from either x86 or x64 subdir
  34. // Required by CefSharp to load the unmanaged dependencies when running using AnyCPU
  35. private static Assembly Resolver(object sender, ResolveEventArgs args)
  36. {
  37. if (args.Name.StartsWith("CefSharp"))
  38. {
  39. string assemblyName = args.Name.Split(new[] { ',' }, )[] + ".dll";
  40. string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
  41. Environment.Is64BitProcess ? "x64" : "x86",
  42. assemblyName);
  43.  
  44. return File.Exists(archSpecificPath)
  45. ? Assembly.LoadFile(archSpecificPath)
  46. : null;
  47. }
  48.  
  49. return null;
  50. }
  51. }
  52. }

三套组合拳打完,CefSharp就可以在AnyCPU模式下使用了

C#:在AnyCPU模式下使用CefSharp的更多相关文章

  1. 基于 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 时代,包括其插件在需要时就引 ...

  2. 微软Azure 经典模式下创建内部负载均衡(ILB)

    微软Azure 经典模式下创建内部负载均衡(ILB) 使用之前一定要注意自己的Azure的模式,老版的为cloud service模式,新版为ARM模式(资源组模式) 本文适用于cloud servi ...

  3. 苹果手机Safari无痕浏览模式下系统登录成功但是页面不跳转

    昨天下午,测试提了一个bug,问题是:在苹果手机Safari无痕浏览模式下系统登录成功但是页面不跳转. 思前想后找了半天没思路,后来经过同事的点拨,说可能是禁用了cookie之类的,反正我也没思路就顺 ...

  4. win10 下visual studio 2015 在调试模式下不能跟踪源文件

    win10 下visual studio 2015 在调试模式下不能跟踪源文件,只要一调试就会关闭(隐藏)打开的文档,非常不方便.经过一番折腾,发现是配置的问题. 如果安装多个版本的VS,请删除对应版 ...

  5. 转:IE兼容模式下 SCRIPT1028: 缺少标识符、字符串或数字

    IE兼容模式下 SCRIPT1028: 缺少标识符.字符串或数字例如下面一段代码 var a = {    x: 1,    y: 2,};alert(a.x);如果在IE的兼容性视图(IE7文档模式 ...

  6. 【配置】检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(非简单设置为【经典】模式)。

      ×   检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(非简单设置为[经典]模式). 我们将ASP.NET程序从IIS6移植到IIS7,可能运行提示以下错误: HTTP 错误 5 ...

  7. Linux学习之CentOS(二十二)--单用户模式下修改Root用户的密码

    在上一篇随笔里面详细讲解了Linux系统的启动过程 (Linux学习之CentOS(二十一)--Linux系统启动详解),我们知道Linux系统的启动级别一共有6种级别,通过 /etc/inittab ...

  8. MVC开发模式下的用户角色权限控制

    前提: MVC开发模式 大概思想: 1.在MVC开发模式下,每个功能都对应着不同的控制器或操作方法名(如修改密码功能可能对应着User/changepd),把每个功能对应的控制器名和操作方法名存到数据 ...

  9. TreeView 使用方法:(在View.Details模式下)

    1.建立TreeView的標題         2.建立TreeView的Item         3.在TreeView的Item中的建立SubItem                  如果將各部 ...

随机推荐

  1. python 中的重要思想

  2. Python version 3.6 required, which was not found in the registry错误解决

    问题: 安装pywin32出现Python version 3.6 required, which was not found in the registry错误解决 解决: 建立一个文件 regis ...

  3. 协议森林09 爱的传声筒 (TCP连接)

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在TCP协议与"流"通信中,我们概念性的讲解了TCP通信的方式 ...

  4. urllib下使用Xpath表达式示例

    urllib下使用Xpath表达式示例 使用xpath表达式需要先将需要匹配的数据转换成tree格式,这就需要先装lxml模块.安装方法可以使用pip安装. 示例代码: import urllib.r ...

  5. POJ1066 Treasure Hunt

    嘟嘟嘟 题意看题中的图就行:问你从给定的点出发最少需要穿过几条线段才能从正方形中出去(边界也算). 因为\(n\)很小,可以考虑比较暴力的做法.枚举在边界中的哪一个点离开的.也就是枚举四周的点\((x ...

  6. HDU 4652 Dice

    嘟嘟嘟 题目大意就是对于一个m面的骰子,回答这么两个问题: 1.求连续扔n次都是同一数字的期望次数. 2.求连续扔n次每一次数字都不相同的期望次数. 对于期望dp特别菜的我来说,这道题已经算是很难了. ...

  7. MFC各个控件之间运用SendMessage()传送CString和char[]字符串,以及int类型数据

    LRESULT SendMessage( HWND hWnd, // handle to destination window UINT Msg, // message WPARAM wParam, ...

  8. Basic Classifiers and Loss Functions

    Linear Classifier and Hing Loss (or Multiclass SVM Loss) Linear Mapping (Score function) Linear Clas ...

  9. cocos2d-x3.0 用CCDictionary写文件

    bool CDownLoad_LocalData::WriteToConfigFile( DownLoadLocalData* downdata ){ CCDictionary* pDict = CC ...

  10. Centos 7安装Grafana 4及结合Zabbix3.2实现可视化监控图形

    上一篇介绍了如何在Centos 7环境下安装zabbix监控,本章继续介绍在Centos 7环境下安装Grafana,并结合Zabbix实现可视化监控图形! 简介: Grafana 是 Graphit ...