Deploying WPF Application with 3rd Party DLLs

后端 未结 6 1046
失恋的感觉
失恋的感觉 2020-12-03 05:37

I\'ve been extremely frustrated trying to deploy a C#/WPF application I\'ve created that has some references to 3rd party DLLs. I created a folder in the project, called

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 06:07

    Thanks to Barrie's answer to this, it helped me greatly. I'm using his answer below, but updating it to work for the latest CEF using Visual Studio 2015.

    NOTE: I am only building/targeting the x86 platform. You may need to change or include x64 in the copy commands below to suit your needs.

    Installing CefSharp

    • Install CefSharp.Wpf through NuGet (I'm using v51.0.0)

      NuGet Library After Install

    • That should put the relevant files in

      $(SolutionDir)packages\CefSharp.Wpf.51.0.0\CefSharp (CefSharp.Wpf) $(SolutionDir)packages\CefSharp.Common.51.0.0\CefSharp (CefSharp.Common) $(SolutionDir)packages\cef.redist.x86.3.2704.1432\CEF (Cef x86 redist) $(SolutionDir)packages\cef.redist.x64.3.2704.1432\CEF (Cef x64 redist)

    Configuring Build

    • To get the CefSharp DLLs to copy to our build folders... I don't believe this is necessary anymore with the later versions of CefSharp. I found that I didn't need any of the "Post-build event command-line" xcopy stuff to get Click-Once to ship it out. (And yes, DevTools works too!)

    Taking care of Visual C++ 2012 Runtime Files

    • (Switched to VCR 2013) I didn't want the user to have to download the whole Visual C++ 2013 Runtime Files as part of the deployment, so through Visual Studio, add the folder lib\Microsoft.VC120.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:\Windows\SysWOW64

      (Didn't see them in C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist)

    At this point, everything should be building. To publish the app with ClickOnce, we need it to push all of the CEF DLLs. You can tweak this accordingly...

    Ensuring CEF and C++ runtime files are deployed with ClickOnce

    • Right click your project in Visual Studio and select "unload project".
    • Right click and select to edit the csproj file.
    • Before the closing tag add the following:

      
      
              
                      %(RecursiveDir)%(Filename)%(Extension)
                      false
              
      
      
              
                      %(RecursiveDir)%(Filename)%(Extension)
                      false
              
      
      
              
              %(RecursiveDir)%(Filename)%(Extension)
              false
              
      
      
              
                      %(RecursiveDir)%(Filename)%(Extension)
                      false
              
      
      
              
                      %(Filename)%(Extension)
                      false
              
      
      
      
    • 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. Having set false you won't see the items in the solution explorer.

    • REMEMBER: I am only building/targeting the x86 platform. You may need to change or include x64 in the copy commands below to suit your needs.

    Publish

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


    (EXTRA INFO) Supporting Older Operating Systems Info Below

    If you need to use CefSharp for older machines (XP & Vista), simply install CefSharp.Wpf through NuGet using the older v47.0.0 version and change your .NET targeting to .NET 4.0 Client Profile.

    Chromium ended support for XP and Vista in April 2016, CefSharp version 47 (or there abouts) still had support for it.

    Another note on a problem and fix for XP:

    There is a Chromium issue for XP deployments. Below is the article describing the fix followed by steps to deploy fix for JBCB.

    Here's the link to the article: https://bitbucket.org/chromiumembedded/cef/issues/1787

    ...in it you'll see a reference to download a "dbghelp.dll". Download and extract.


    YOU CAN TAKE A POST-INSTALL APPROACH LIKE BELOW OR CHOOSE TO INCLUDE THE DLL ALONG WITH YOUR OTHER PUBLISHED FILES. I'M CHOOSING NOT TO DEPLOY THE EXTRA DLL AND ONLY DEPLOY ON XP MACHINES (WE ONLY HAVE FEW) MANUALLY.


    Take these steps to fix deployment on an XP machine:

    1. Install the CefSharp Browser on the XP machine (via Click-Once)
    2. Copy the "dbghelp.dll"
    3. Paste it in the local install directory on the XP machine (per the instructions in previous link: along side the "libcef.dll" file).

    NOTE: For click-once installs, will be in a sub-folder under this location:

    C:\Documents and Settings\\Local Settings\Apps\2.0\
    

提交回复
热议问题