且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用第三方DLL部署WPF应用程序

更新时间:2023-11-14 18:51:40

我一直在撕裂我的头发,试图在今天早上解决这个问题,最终找到解决方案。看来你已经知道CEFSharp工作中需要哪些DLL,但是我以为我会运行这个,以防其他人遇到同样的问题。我有一个C#WPF应用程序,我正在使用CEFSharp作为Web视图。我正在使用CEFSharp v1,因为我需要他们提供的JavaScript - > C#桥接在v3中尚未实现。这是我在设计项目中所执行的粗暴步骤(我使用的是VS2013,但这可能会在VS2012中运行)。

I've been tearing my hair out trying to fix this very problem this morning and eventually found the solution. It seems you already know which DLLs etc. you need for CEFSharp to work but I thought I would run through this in case anyone else is having the same problem. I have a C# WPF application and I'm using CEFSharp as the web view. I'm using CEFSharp v1 because I need the JavaScript -> C# bridge they provide which isn't yet implemented in v3. Here are the rough steps I went through in setting up the project (I'm using VS2013 but this will probably work in VS2012).


  • 通过NuGet安装CefSharp.Wpf(我正在使用v1.25.7)

  • 应该将相关文件放在 $(SolutionDir)packages\CefSharp.Wpf.1.25.7\cef

  • Install CefSharp.Wpf through NuGet (I'm using v1.25.7)
  • That should put the relevant files in $(SolutionDir)packages\CefSharp.Wpf.1.25.7\cef

  • 要将CefSharp DLL复制到我们的构建文件夹,请右键单击项目,选择属性 - >构建事件并在后构建事件命令行中输入以下内容:

  • To get the CefSharp DLLs to copy to our build folders, right-click on your project, select Properties -> Build Events and enter the following in the "Post-build event command line":


xcopy$(SolutionDir)packages \\ CefSharp.Wpf.1.25.7\cef *$(TargetDir)/ s / y / i

xcopy "$(SolutionDir)packages\CefSharp.Wpf.1.25.7\cef*" "$(TargetDir)" /s /y /i


  • 现在应该从cef文件夹以及 devtools_resources.pak 文件和 locales 中复制所有必需的DLL >文件夹及其内容。我需要他们在我的项目中,因为我需要铬开发工具。

  • That should now copy all of the required DLLs from the cef folder as well as the devtools_resources.pak file and the locales folder plus its contents. I require them in my project as I need the chromium dev tools.


    • 我不希望用户通过Visual Studio下载整个Visual C ++ 2012运行时文件作为部署的一部分,添加文件夹 Lib \Microsoft.VC110.CRT 并添加3个DLL( msvcp110.dll msvcr110.dll vccorlib110.dll )从机器上的以下文件夹到您刚刚在项目中创建的文件夹:

    • I didn't want the user to have to download the whole Visual C++ 2012 Runtime Files as part of the deployment so through Visual Studio, add the folder Lib\Microsoft.VC110.CRT and add the 3 DLLs (msvcp110.dll, msvcr110.dll, vccorlib110.dll) from the following folder on your machine to the folder you just created in your project:

    C:\程序文件(x86)\Microsoft Visual Studio 11.0 \VC\redist\x86\Microsoft.VC110.CRT

    在Visual Studio中选择3个DLL文件,右键单击 - >属性。确保构建操作设置为无,复制到输出目录设置为不要复制。现在,您需要添加另一个后期构建事件,以确保这些已正确复制(即复制到根目录,以便它们与CEF dll和项目exe一起使用)进行调试。

    Select the 3 DLL files in Visual Studio, right-click -> properties. Make sure Build Action is set to "None" and Copy to Output Directory is set to "Do not copy". Now you need to add another post-build event to make sure these are copied properly (i.e. copied to the root so they sit alongside the CEF dlls and your project exe) for debug.

    右键单击您的项目,选择属性 - >构建事件,并在CEF的其他xcopy命令之后的后构建事件命令行中输入以下内容:

    Right-click on your project, select Properties -> Build Events and enter the following in the "Post-build event command line" just after your other xcopy command for CEF:


    xcopy$(ProjectDir)Lib\Microsoft.VC110.CRT *。*$(TargetDir)/ s / y / i

    xcopy "$(ProjectDir)Lib\Microsoft.VC110.CRT*.*" "$(TargetDir)" /s /y /i


  • 在这一点上,一切都应该建立。要使用ClickOnce发布应用程序,我需要将所有CEF DLL推出,并确保chrome dev工具所需的文件/文件夹。如果您不需要开发工具或所有DLL,那么您可以相应地进行调整。

    At this point, everything should be building. To publish the app with ClickOnce, I need it to push all of the CEF DLLs out as well as ensuring the files/folders required for chromium dev tools are present. If you don't need the dev tools or all of the DLLs then you can tweak this accordingly.


    • 右键单击Visual Studio中的项目并选择卸载项目。

    • 右键单击并选择编辑csproj文件。

    • 关闭< / Project> 标签添加(对于格式在这里道歉):

    • Right click your project in Visual Studio and select "unload project".
    • Right click and select to edit the csproj file.
    • Before the closing </Project> tag add this (apologies for the formatting here):

    < ItemGroup>

    < Content Include =$(SolutionDir)packages\CefSharp.Wpf.1.25.7\cef\ ** \ *&gt ;

    < Link>%(RecursiveDir)%(Filename)%(Extension)< / Link>

    < Visible> false< / Visible>

    < / Content> / code>

    < / ItemGroup>

    <ItemGroup>
    <Content Include="$(SolutionDir)packages\CefSharp.Wpf.1.25.7\cef\**\*">
    <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
    <Visible>false</Visible>
    </Content>
    </ItemGroup>

    < ItemGroup>

    < Content Include =$(ProjectDir)Lib \Microsoft.VC110.CRT \ ** \ *>

    < Link>%(RecursiveDir)%(Filename)%(Extension)链接>

    < Visible> false< / Visible>

    < / Content>

    < / ItemGroup>

    <ItemGroup>
    <Content Include="$(ProjectDir)Lib\Microsoft.VC110.CRT\**\*">
    <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
    <Visible>false</Visible>
    </Content>
    </ItemGroup>


    • 将cef文件夹中的所有内容添加到项目中,并确保将C ++二进制文件复制到部署的项目根目录中。在CEF的情况下,我使用Include和%(RecursiveDir)结尾处的 \ ** \ * 语法/ code>,以确保所有文件都被复制,以及保存其内容和结构的 locales 文件夹。设置< Visible> false< / Visible> ,您将看不到解决方案资源管理器中的项目。

    • That will add everything from the cef folder into the project and make sure the C++ binaries are copied to the root of the project on deployment. In my case for CEF, I'm using the \**\* syntax at the end of the Include and %(RecursiveDir) to ensure all of the files are copied as well as the locales folder with its contents and structure preserved. Having set <Visible>false</Visible> you won't see the items in the solution explorer.

    现在,如果您发布应用程序,它应该复制所有必需的文件和文件夹。

    Now if you publish your app, it should copy over all of the required files and folders.