• 引用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位

  • 相关阅读:
    位运算 & 网络序字节序
    TFTP & commons-net-3.3.jar
    存储过程
    poj1185-炮兵阵地(状态压缩dp)
    hdu4570-区间dp
    codevs1026-dp(记忆化搜索)
    hdu1494 跑跑卡丁车(动态规划)
    hdu5094-Maze
    hdu4403- A very hard Aoshu problem(搜索)
    hdu2510-符号三角形(dfs+打表)
  • 原文地址:https://www.cnblogs.com/plain-heart/p/CefSharp_AnyCPU.html
Copyright © 2020-2023  润新知