我使用C#
项目创建一个Winform
CefSharp
应用程序。
该应用程序在调试模式下运行良好,但是当我尝试使用VS2013对其进行发布时,它在应用程序开始运行之前崩溃。
这是我的program.cs文件:
[STAThread]
static void Main()
{
AppDomain.CurrentDomain.AssemblyResolve += Resolver;
LoadApp();
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void LoadApp()
{
var settings = new CefSettings();
settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
Environment.Is64BitProcess ? "x64" : "x86",
"CefSharp.BrowserSubprocess.exe");
settings.CachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\TelegramParser\CEF";
settings.IgnoreCertificateErrors = true;
settings.WindowlessRenderingEnabled = true;
settings.SetOffScreenRenderingBestPerformanceArgs();
Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);
Application.Run(new Form1());
}
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;
}
从CefSharp
Wiki上我了解到有一些文件丢失。知道可能是什么问题吗?
我使用Visual Studio 2013
运行和发布项目。
我正在使用Any CPU
进行编译。
<ItemGroup>
<Content
Include="$(SolutionDir)packages\cef.redist.x86.3.3497.1841\CEF\**\*" Exclude="$(SolutionDir)packages\cef.redist.x86.3.3497.1841\CEF\x86\**\*;$(SolutionDir)packages\cef.redist.x86.3.2526.1362\CEF\locales\**\*.pak">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="$(SolutionDir)packages\cef.redist.x86.3.3497.1841\CEF\**\en-GB.*;$(SolutionDir)packages\cef.redist.x86.3.3497.1841\CEF\**\en-US.*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="$(SolutionDir)packages\cef.redist.x86.3.3497.1841\CEF\x86\**\*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="$(SolutionDir)packages\CefSharp.Common.69.0.0\CefSharp\x86\**\CefSharp.BrowserSubprocess.*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
<ItemGroup>
<Content
Include="$(SolutionDir)packages\cef.redist.x64.3.3497.1841\CEF\**\*" Exclude="$(SolutionDir)packages\cef.redist.x64.3.3497.1841\CEF\x64\**\*;$(SolutionDir)packages\cef.redist.x86.3.2526.1362\CEF\locales\**\*.pak">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="$(SolutionDir)packages\cef.redist.x64.3.3497.1841\CEF\**\en-GB.*;$(SolutionDir)packages\cef.redist.x64.3.3497.1841\CEF\**\en-US.*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="$(SolutionDir)packages\cef.redist.x64.3.3497.1841\CEF\x64\**\*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="$(SolutionDir)packages\CefSharp.Common.69.0.0\CefSharp\x64\**\CefSharp.BrowserSubprocess.*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
我添加了此内容,现在应用程序因以下错误而崩溃:
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in App.exe
Additional information: Could not load file or assembly 'CefSharp.Core.dll' or one of its dependencies. The specified module could not be found.
答案 0 :(得分:1)
任何CPU都是问题。
您可以选择x64或x86平台。
确保已添加对CefSharp.Winforms nuget的引用
确保将解决方案的平台显式设置为x86 / x64,而不是任何CPU。
在配置文件中添加以下运行时绑定:
dataset = tf.data.Dataset.from_tensor_slices(dataset)
CSProj文件应设置以下属性:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="x86"/>
</assemblyBinding>
</runtime>
请参阅this article-逐步介绍了在Winforms中设置CEFSharp浏览器的过程。