简体   繁体   English

System.IO.FileNotFoundException - 在发行版中找不到 CefSharp.Core.dll

[英]System.IO.FileNotFoundException - CefSharp.Core.dll not found in release

I've downloaded the CefSharp extension with NuGet reposity and I've tested it with Microsoft Visual Studio.我已经下载了带有 NuGet 存储库的 CefSharp 扩展,并使用 Microsoft Visual Studio 对其进行了测试。
I've used the default code, it is:我使用了默认代码,它是:

namespace WebBrowser
{
    public partial class WebForm : Form
    {
        public WebForm()
        {
            InitializeComponent();
            InitBrowser();
        }

        public ChromiumWebBrowser browser;
        public void InitBrowser()
        {
            Cef.Initialize(new CefSettings());
            browser = new ChromiumWebBrowser("www.google.com");
            this.Controls.Add(browser);
            browser.Dock = DockStyle.Fill;
        }

        private void WebForm_Load(object sender, EventArgs e)
        {

        }
    }
}

If I run the project in debug, it works well: it open a window with Google.如果我在调试中运行该项目,它运行良好:它打开一个带有 Google 的窗口。 But if I compile the project and I install it with the setup, I get always an error:但是,如果我编译项目并使用 setup 安装它,我总是会收到一个错误:
System.IO.FileNotFoundException: Could not load file or assembly 'CefSharp.Core.dll' or one of its dependencies. System.IO.FileNotFoundException:无法加载文件或程序集“CefSharp.Core.dll”或其依赖项之一。

I've searched on Google, I've tried adding xcopy "$(SolutionDir)packages\\cef.redist.x86.3.2987.1601\\CEF*" "$(TargetDir)" /s /y /i in post compilation and other ways, but nothing works.我已经搜索在谷歌,我已经尝试添加xcopy "$(SolutionDir)packages\\cef.redist.x86.3.2987.1601\\CEF*" "$(TargetDir)" /s /y /i在后编译等方法,但没有任何效果。

What can I try?我可以尝试什么?

Ok, finally I found what is the cause of your problem.好的,我终于找到了您的问题的原因。 CefSharp needs to have some files in root application directory. CefSharp 需要在根应用程序目录中有一些文件。

In setup project, when selecting files for Application folder, choose Add => File... instead of Add => Project Output... .在安装项目中,当为 Application 文件夹选择文件时,选择Add => File...而不是Add => Project Output... Then navigate to your build folder and pick all files.然后导航到您的构建文件夹并选择所有文件。 This will create 1 to 1 copy of your output files when running setup executable.这将在运行 setup 可执行文件时创建输出文件的 1 对 1 副本。

I had a similar issue and solved it by installing the following redistributable:我遇到了类似的问题,并通过安装以下可再发行组件解决了这个问题:

Microsoft Visual C++ 可再发行组件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM