使用第三方DLL部署WPF应用程序 [英] Deploying WPF Application with 3rd Party DLLs

查看:362
本文介绍了使用第三方DLL部署WPF应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常沮丧地试图部署一个C#/ WPF应用程序,我创建了一些对第三方DLL的引用。我在项目中创建了一个名为 lib 的文件夹,其中放置了所有这些DLL。在VS2012中,我通过浏览到该文件夹​​并选择所有的DLL来添加引用。 将本地复制设置为 true 。一切都很好,当我建立和运行,但当我选择发布,并创建一个OneClick安装程序,事情并不顺利。在发布向导中,我将其设置为从磁盘进行安装,并将其设置为从不检查更新。我拿这个文件夹,将其放在闪存驱动器上,将其插入另一台PC,运行安装程序,并引发异常。我相信我知道发生了什么,但是我无法弄清楚如何打包它以正确部署。

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 lib, where I placed all of these DLLs. In VS2012, I added the references by browsing to that folder, and selecting all the DLLs. Copy Local is set to true for all. Everything is fine when I build and run, but when I choose publish, and create a OneClick Installer, things aren't so smooth. During the publish wizard, I set it to install from disk, and set it to never check for updates. I take that folder, place it on a flash drive, plug it into another PC, run the setup, and it throws an Exception. I believe I know what is happening, but I cannot figure out how to package this in order to deploy it correctly.

我的一个DLL是一个DLL的C#包装这是为C ++项目设计的。我们会说,应用程序需要 DLL1 DLL1 要求 DLL2 DLL2 不能作为项目的引用添加,因为它不是一个 .NET DLL。 DLL1 要求 DLL2 在同一个文件夹中,以便将其取代。我正在使用 CefSharp ,其中包含 Chromium Embedded Framework

One of my DLLs is a C# wrapper to a DLL that is designed for a C++ project. We'll say, Application requires DLL1 and DLL1 requires DLL2. DLL2 cannot be added as a reference in the project because is not a .NET DLL. DLL1 requires DLL2 to be in the same folder in order to pick it up. I'm using CefSharp which wraps the Chromium Embedded Framework.

我尝试将CefSharp.dll所需的DLL放在 publish / Application Files 目录,但它没有工作。我注意到,所有来自VS2012的DLL都有一个 .deploy 扩展名,我甚至去添加了这个扩展名,看看它是否正在扫描拿起来,但是它也不行。这是我第一次为Windows应用程序进行开发和部署,并且我看过的MSDN或博客文章上的所有教程似乎都没有涵盖这种情况,我在部署管理器中看不到任何其他选项来处理这些

I've tried placing the required DLLs for CefSharp.dll in the publish/Application Files directory, but it did not work. I noticed that all of the DLLs that are there from VS2012 have a .deploy extension on them, I even went and added that extension on to see if it was scanning for that to pick up, but it did not work either. This is my first time doing development and deployment for a Windows application and all of the tutorials on MSDN or blog posts I've read do not seem to cover this case, and I do not see any other options in the deployment manager to handle these types of cases.

如果有帮助,抛出的异常代码是: CLR20r3

If it helps, the Exception Code that is thrown is: CLR20r3

当我抓到并显示异常时,我提供的所有信息基本上都表示 CefSharp.dll或其中一个依赖关系无法加载 DLL2 之前,我已经不在与$ code> DLL1 相同的文件夹。

When I catch and display Exception, all of the info I am provided basically says CefSharp.dll or one of it's dependencies cannot be loaded. Which I've gotten before when DLL2 was not in the same folder as DLL1.

任何人都可以提供如何从VS2012部署如何处理这种情况的帮助?

Can anyone provide help on how to deploy from VS2012 with a situation like this?

提前感谢!

编辑:信息更新

我试图将调试版本推送到没有Visual Studio的测试机器安装。当构建 CefSharp 或任何其他C ++运行库 DLL 时,它将寻找所有的Debug版本的code> DLL 通常名称相同,但最后添加字母d。如下所述,C ++运行时的调试版本不可重新分发。不是你不能手动将这些 DLLs 添加到您的项目中,并将它们设置为复制始终,但这是一种一个黑客的工作。我从头开始一个新项目,添加了所有版本的DLL,内置,一切都很好。

I was attempting to push a debug build version to a test machine without Visual Studio installed. When building for CefSharp or any other C++ Runtime DLL, it will look for all of the Debug versions of the DLL which are usually the same name, but with the letter 'd' added to the end. As mentioned below, the Debug version of the C++ Runtime is not redistributable. Not that you can't manually add those DLLs to your project and set them as Copy Always, but that's kind of a hack job. I started a new project from scratch, added all Release versions of the DLLs, built, and everything was fine.

推荐答案

我一直在撕裂我的头发,试图在今天早上解决这个问题,最终找到解决方案。看来你已经知道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 文件夹及其内容。我需要他们在我的项目中,因为我需要铬开发工具。

  • 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\ ** \ *> ;

    < 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.

    这篇关于使用第三方DLL部署WPF应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆