zoukankan      html  css  js  c++  java
  • 引用CefSharp编译支持AnyCpu的办法

    CefSharp从51版本以后开始支持AnyCpu编译模式

    第一步:App.config的configuration下增加一个配置:

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

    第二步:编辑项目的csproj文件(可以用记事本,也可以先右键卸载项目,然后再右键选编辑项目)

    在csproj文件的PropertyGroup节点下第一行增加一个配置项

    <CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport>

    第三步:Program.cs的内容如下:

    static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
                AppDomain.CurrentDomain.AssemblyResolve += Resolver;
                LoadApp();
            }
            [MethodImpl(MethodImplOptions.NoInlining)]
            private static void LoadApp()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                CefSettings settings = new CefSettings
                {
                    Locale = "zh-CN",
                    BrowserSubprocessPath = @"x86CefSharp.BrowserSubprocess.exe"
                };
                Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);
                Application.Run(new Login());
            }
     
            // Will attempt to load missing assembly from either x86 or x64 subdir
            private static Assembly Resolver(object sender, ResolveEventArgs args)
            {
                if (args.Name.StartsWith("CefSharp"))
                {
                    string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll";
                    string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                                                           Environment.Is64BitProcess ? "x64" : "x86",
                                                           assemblyName);
     
                    return File.Exists(archSpecificPath)
                               ? Assembly.LoadFile(archSpecificPath)
                               : null;
                }
                return null;
            }
        }
    

     注意: 配置管理器里面的还是要设置平台为x86(为了让cefsharp.common可以编译过去), 然后右键项目属性, 在生成标签页设置目标平台为AnyCPU, 首选32位

  • 相关阅读:
    Luogu 4206 [NOI2005]聪聪与可可
    【Luogu】P3708Koishi的数字游戏(数论)
    【Luogu】P1850换教室(期望DP)
    【Luogu】P1231教辅的组成(拆点+Dinic+当前弧优化)
    【Luogu】P3865ST表模板(ST表)
    【Luogu】P3376网络最大流模板(Dinic)
    【Luogu】P1005矩阵取数游戏(高精度+DP)
    【Luogu】P2324骑士精神(IDA*)
    【Luogu】P3052摩天大楼里的奶牛(遗传算法乱搞)
    洛森地图半成品
  • 原文地址:https://www.cnblogs.com/plain-heart/p/CefSharp_AnyCPU.html
Copyright © 2011-2022 走看看