开发者

Using the same modules in multiple projects

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

My problem i开发者_开发问答s 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.

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?


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. Create a new "Class Library" project in Visual Studio.

  2. Move all of your modules into that project.

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

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

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.


The Solution offered by Marcel J. Kloubert is the better one. (because in the setup you described its too easy to accidently break functionality.)

But you can do what you asked for by:
1) right click your project
2) choose Add -> Existing item
3) select your file
4) click on the little thingy right next of Add
5) choose Add as Link


You can move the modules to a separate, central library project which can be included in each solution of your projects.

In each project you can add a reference to that library if you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜