Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the same modules in multiple projects

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

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.

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?

like image 641
Andreas Vinther Avatar asked Dec 30 '10 05:12

Andreas Vinther


2 Answers

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.

like image 94
Cody Gray Avatar answered Sep 24 '22 09:09

Cody Gray


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

like image 24
NULL Avatar answered Sep 25 '22 09:09

NULL