Using the same modules in several projects

I am using Visual Studio 2010 and encoding in VB.NET.

My problem is that I have compiled all the modules that I wrote and intend to reuse, and put them in a separate folder. When I want to add a module from the above folder to any project, it takes a copy of the module and the location in the project source code folder instead of the link to the module in the folder containing all the other modules.

Is it possible to include a module in my project and leave it in a folder with all other modules, so when I improve the module, it will affect all projects that use / link to this module. Instead of having to manually copy the new module to all projects that use / reference the module. Right now I have several instances of the same module that I need to update manually when I improve the code or add functionality?

+6
oop visual-studio visual-studio-2010
source share
3 answers

You are certainly on the right track while trying to minimize code duplication! The best thing you need to do is compile your code into a reusable class library that you can use from multiple projects.

  • Create a new Class Library project in Visual Studio.

  • Move all your modules to this project.

  • Compile this project and pay attention to the location of the generated DLL file.

  • Add a link to this DLL file to each of the other projects that you want to use to call the methods open by your modules.

The advantage of this method in adding separate code files to each project is that if you ever update or modify code in a class library, all you have to do is recompile the class library.

In addition, if you plan to deploy several different applications that rely on the same modules, this will allow each of them to dynamically call methods that are presented as part of the class library.

+7
source share

The solution proposed by Marcel J. Clubert is the best. (because in the setup, you described it too easily to accidentally break functionality.)

But you can do what you asked for:
1) right click your project
2) select Add → Existing item
3) select file
4) click on the little item next to Add
5) select "Add as link"

+6
source share

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

In each project, you can add a link to this library if you want.

0
source share

All Articles