在 Visual Studio 中复制 DLL 的依赖项 [英] Copying a DLL's dependencies in Visual Studio

查看:26
本文介绍了在 Visual Studio 中复制 DLL 的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Visual Studio 中设置项目以复制项目引用之一所依赖的第三方 DLL?

How can I set up a project in Visual Studio to copy the third-party DLLs that one of the project's references depends on?

我有一个主应用程序项目和一个类库 DLL.主应用程序引用类库DLL,DLL本身引用了一些第三方DLL.当我编译主应用程序时,它会自动将类库 DLL 复制到其输出目录,但不会复制第三方 DLL.

I have a main application project and a class library DLL. The main application references the class library DLL, and the DLL itself references some third-party DLLs. When I compile the main application, it automatically copies the class library DLL to its output directory, but it does not copy the third-party DLLs.

我不想从主应用程序项目中添加对第三方 DLL 的引用,因为主应用程序不使用它们,它们只被类库使用.

I do not want to add references to the third-party DLLs from the main application project because the main application does not use them, they're only used by the class library.

推荐答案

您可以使用项目属性窗口实现此目的.Visual Studio 允许您定义在构建之前或之后发生的事件.要进入项目属性窗口,只需在解决方案资源管理器窗口中右键单击您的项目,然后单击属性".从左侧转到构建事件"选项卡.

You can achieve this with the project properties window. Visual Studio allows you to define events to occur, before, or after building. To get to the project properties window simply right-click on your project in the solution explorer window and click on 'properties'. From the left hand side go to the 'build events' tab.

在构建后框中键入一些复制命令.例如:

In the post-build box type in a few copy commands. For example:

copy "$(SolutionDir)mydll.dll" "$(TargetDir)"

其中 $(SolutionDir)$(TargetDir) 都是预定义的变量.标准语法如下:

Where $(SolutionDir) and $(TargetDir) are both predefined variables. The standard syntax is as follows:

copy "source directory and file name" "destination directory"

如果您单击编辑后构建..."按钮,它将弹出一个框,其中包含您可以插入的这些预定义变量的列表(例如 $(SolutionDir) 和 <代码>$(TargetDir))

If you click on the 'edit post build...' button it will bring up a box which has a listing of these predefined variables that you can insert (like $(SolutionDir) and $(TargetDir))

附带说明,这是复制其他文件(例如自定义配置文件、图像或您的项目可能具有的任何其他依赖项)的有用过程.

As a side note, this is a useful process for copying other files, such as custom configuration files, images, or any other dependencies your project may have.

这篇关于在 Visual Studio 中复制 DLL 的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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