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

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

问题描述

在尝试部署我创建的 C#/WPF 应用程序时,我非常沮丧,该应用程序有一些对 3rd 方 DLL 的引用.我在项目中创建了一个名为 lib 的文件夹,我在其中放置了所有这些 DLL.在 VS2012 中,我通过浏览到该文件夹​​并选择所有 DLL 添加了引用.Copy Local 全部设置为 true.当我构建和运行时一切都很好,但是当我选择发布并创建 OneClick 安装程序时,事情就不那么顺利了.在发布向导期间,我将其设置为从磁盘安装,并将其设置为从不检查更新.我拿了那个文件夹,把它放在一个闪存驱动器上,把它插到另一台电脑上,运行安装程序,它抛出一个异常.我相信我知道发生了什么,但我不知道如何打包以正确部署它.

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 是为 C++ 项目设计的 DLL 的 C# 包装器.我们会说,Application 需要 DLL1DLL1 需要 DLL2.DLL2 不能作为引用添加到项目中,因为它不是 .NET DLL.DLL1 要求 DLL2 位于同一个文件夹中才能提取它.我正在使用 CefSharp 包装了 Chromium 嵌入式框架.

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 或其依赖项之一无法加载.我以前在 DLL2DLL1 不在同一个文件夹中时得到的.

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 构建时,它将查找 DLL 的所有调试版本,这些版本通常是相同的名称,但在末尾添加了字母 'd'.如下所述,C++ 运行时的调试版本不可再发行.并不是说您不能手动将那些 DLL 添加到您的项目中并将它们设置为 Copy Always,但这是一种黑客工作.我从头开始了一个新项目,添加了 DLL 的所有 Release 版本,构建了,一切都很好.

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)packagesCefSharp.Wpf.1.25.7cef
  • 要将 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)packagesCefSharp.Wpf.1.25.7cef*";$(TargetDir)"/s/y/i

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

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

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

    仔细检查您的项目引用是否包含 CefSharpCefSharp.Wpf.这应该由 NuGet 处理.

    Double-check your project references contain CefSharp and CefSharp.Wpf. That should have been taken care of by NuGet.

    • 我不希望用户在部署过程中下载整个 Visual C++ 2012 运行时文件,因此通过 Visual Studio 添加文件夹 LibMicrosoft.VC110.CRT 并将计算机上以下文件夹中的 3 个 DLL(msvcp110.dllmsvcr110.dllvccorlib110.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 LibMicrosoft.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:Program Files (x86)Microsoft Visual Studio 11.0VC edistx86Microsoft.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)LibMicrosoft.VC110.CRT*.*";$(TargetDir)"/s/y/i

    xcopy "$(ProjectDir)LibMicrosoft.VC110.CRT*.*" "$(TargetDir)" /s /y /i

  • 此时,一切都应该在构建中.要使用 ClickOnce 发布应用程序,我需要它推出所有 CEF DLL,并确保存在 Chrome 开发工具所需的文件/文件夹.如果您不需要开发工具或所有 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 中右键单击您的项目并选择卸载项目".

    • Right click your project in Visual Studio and select "unload project".

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

    Right click and select to edit the csproj file.

    在结束 </Project> 标签之前添加这个

    Before the closing </Project> tag add this

    <ItemGroup>
       <Content Include="$(SolutionDir)packagesCefSharp.Wpf.1.25.7cef***">
         <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
         <Visible>false</Visible>
      </Content>
    </ItemGroup>
    
    <ItemGroup>
       <Content Include="$(ProjectDir)LibMicrosoft.VC110.CRT***">
          <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
          <Visible>false</Visible>
      </Content>
    </ItemGroup>
    

  • 这会将 cef 文件夹中的所有内容添加到项目中,并确保在部署时将 C++ 二进制文件复制到项目的根目录中.对于 CEF,我在 Include 和 %(RecursiveDir) 末尾使用 *** 语法来确保复制所有文件以及保留其内容和结构的 locales 文件夹.设置 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. 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.

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

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