CefSharp从51版本以后开始支持AnyCpu编译模式
第一步:App.config的configuration下增加一个配置:
第二步:编辑项目的csproj文件(可以用记事本,也可以先右键卸载项目,然后再右键选编辑项目)
在csproj文件的PropertyGroup节点下第一行增加一个配置项
第三步:Program.cs的内容如下:
static class Program
{
///
/// 应用程序的主入口点。
///
[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 = @"x86\CefSharp.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;
}
}
参考:https://github.com/cefsharp/CefSharp/issues/1714