在Visual Studio 2013中向您自己的DLL项目添加依赖项/引用 [英] Add a dependency / reference to your own DLL project in Visual Studio 2013

查看:345
本文介绍了在Visual Studio 2013中向您自己的DLL项目添加依赖项/引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一些不同的应用程序,我希望它们都共享同一个DLL库。共享的DLL是我创建的,因此,我真的希望每个应用程序都对DLL有依赖性,以便使DLL与应用程序使用相同的解决方案。然后,DLL应该在应用程序运行之前将自身复制到应用程序的bin文件夹中。

I have been working on a few different applications and I want them all to share the same DLL library. The shared DLL is one that I created, so really I want each application to have a dependency on the DLL so that the DLL gets built in the same solution as the application. Then the DLL should copy itself to the application's bin folder before the application runs.

弄清楚如何执行此操作后,似乎只需要花费5分钟左右,但是很遗憾,我花了一个小时才弄清楚。部分原因是类似的问题是指旧版本的Visual Studio或第3方DLL。所以我想我应该把步骤发布在这里。

After figuring out how to do this, it seems that it should have only taken about 5 minutes, but unfortunately it took me an hour to figure out. That's partly because similar questions were referring to older versions of Visual Studio, or referring to 3rd party DLLs. So I thought I'd post the steps here.

推荐答案


  1. 您应该已经有一个现有项目和DLL的解决方案。为依赖于DLL的新应用程序打开解决方案

  2. 在解决方案资源管理器(您的解决方案名称)中突出显示第一行,然后转到文件菜单并选择添加>现有项目。 ..

  3. 浏览到DLL的项目文件并选择它。这样会将DLL项目添加到您的解决方案中

  4. 尽管您的项目现在处于同一解决方案中,但实际上并没有为您的主项目创建引用。因此,现在右键单击原始项目(应在解决方案资源管理器中的第二行),然后选择添加>参考...

  5. 参考管理器将出现。确保在左侧选择了解决方案>项目。然后,您应该会在右侧看到您的DLL项目。将鼠标悬停在它上面时,将出现一个复选框。选择复选框。单击确定。

  6. 最后,请确保正确设置了项目依赖项。再次,在解决方案资源管理器中右键单击您的解决方案(顶行)。选择项目依赖项...

  7. 在项目下拉列表中,确保已选择您的主项目。然后在下面的依赖于列表中,选中DLL项目的复选框。

  1. You should already have one existing project and solution for your DLL. Open your solution for your new application that depends on your DLL
  2. Highlight the top line in your Solution Explorer (your solution name), then go to the File menu and choose Add > Existing Project...
  3. Browse to the project file for your DLL and select it. That will add the DLL project to your solution
  4. Although your projects are now in the same solution, that didn't actually create a reference for your main project. So now right-click on your original project (should be 2nd line in your Solution Explorer) and choose Add > Reference...
  5. The Reference Manager will appear. Be sure that you have Solution > Projects selected on the left. Then you should see your DLL project listed on the right. When you hover over it, a checkbox will appear. Select the check box. Click OK.
  6. Last, be sure that your Project Dependencies are set correctly. Again, right-click on your Solution in Solution Explorer (top line). Choose Project Dependencies...
  7. In the Projects drop down, make sure your main project is selected. Then in the Depends On list below, check the box for your DLL project.

现在,当您构建解决方案时,它将首先构建DLL,然后将其复制到您的应用程序bin文件夹中,然后生成您的应用程序。该参考还允许您在代码文件中引用DLL,例如使用MyLib;。 C#或VB的导入MyLib

Now when you Build your solution, it will first build the DLL, then copy it to your applications bin folder, then build your application. The Reference will also allow you to refer to the DLL in your code files, for example with "using MyLib;" for C#, or "Imports MyLib" for VB

这篇关于在Visual Studio 2013中向您自己的DLL项目添加依赖项/引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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