在多个项目中使用相同的模块 [英] Using the same modules in multiple projects

查看:275
本文介绍了在多个项目中使用相同的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2010和编码VB.NET。

I'm using Visual Studio 2010 and coding in VB.NET.

我的问题是,我已经收集了所有我写的模块,并打算重用,并把他们安置在一个单独的文件夹。 当我想从上面的文件夹以任何给定的项目添加一个模块,它需要的,而不是引用该模块包含所有其他模块的文件夹中的模块和地方项目的源$ C ​​$ C文件夹的副本。

My problem is that I've collected all the modules I've written and intend to reuse and placed them in a separate folder. When I want to add a module from the above folder to any given project, it takes a copy of the module and places in the project's source code folder, instead of referencing the module in the folder containing all the other modules.

是否有可能包括在我的项目模块,让它在文件夹中的所有其它模块,这样,当我改善后的模块,它会影响到所有使用该项目/引用该模块。相反,我有新的模块,手动复制到所有使用该项目/引用模块。现在,我有我需要手动更新时,我提高code或添加功能完全相同的模块的多个实例?

Is it possible to include a module in my project and leave it in the folder with all the other modules, so that when I improve upon a module, it'll affect all the projects that uses/references that module. Instead of me having to manually copy the new module to all the projects that uses/references the module. Right now I have multiple instances of the exact same module that i need to update manually when I improve code or add functionality?

推荐答案

您是绝对正确的轨道上,试图最大限度地减少code复制!为你做的最好的事情是编译code到可重用的类库,您可以从多个项目中使用。

You're definitely on the right track in trying to minimize code duplication! The best thing for you to do is compile your code into a reusable class library that you can use from multiple projects.

  1. 在Visual Studio中的一个新的类库项目。

  1. Create a new "Class Library" project in Visual Studio.

移动所有的模块到该项目中。

Move all of your modules into that project.

编译该项目,并注意生成的DLL文件的位置。

Compile that project, and note the location of the DLL file that is generated.

添加一个引用到DLL文件在每次希望能够调用你的模块暴露方法等项目。

Add a reference to that DLL file to each of the other projects that you wish to be able to call methods exposed by your modules.

此方法在将您的个性化code文件对每个项目的好处是,如果你曾经更新或修改code的类库,所有你需要做的就是重新编译类库

The benefit of this method over adding your individual code files to each project is that if you ever update or modify the code in the class library, all you'll have to do is recompile the class library.

此外,如果您计划部署几个依赖于相同的模块不同的应用程序,这将让他们每个人的动态调用暴露类库的一部分的方法。

Additionally, if you plan on deploying several different applications that rely on the same modules, this will allow each of them to dynamically call the methods exposed as part of the class library.

这篇关于在多个项目中使用相同的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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