从cefsharp57开始就支持anycpu了,不过需要一些设置:
1.首先要打开*.csprj文件,添加节点 <CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport>
<PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> ... <CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport> </PropertyGroup>
2.修改app.config文件
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" /> </startup> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <probing privatePath="x86"/> </assemblyBinding> </runtime> </configuration>
3.最后在App.xaml.cs的构造函数里添加:
1 [MethodImpl(MethodImplOptions.NoInlining)] 2 private static void CefInit() 3 { 4 CefSharp.CefSettings settings = new CefSharp.CefSettings(); 5 ... 6 settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, 7 Environment.Is64BitOperatingSystem ? "x64" : "x86", 8 "CefSharp.BrowserSubprocess.exe"); 9 CefSharp.Cef.Initialize(settings, false, null); 10 }
编译运行,成功。