Updating classes used in multiple projects?

I have several classes that are abstracted in such a way that I can use them in several projects. I always work on these classes, optimizing, adding, etc. Therefore, when I optimize something in one of these classes, then I need to copy this new version into every project that I remember using it. This is not a good way to do this, but is there a better way?

thanks

+4
source share
5 answers

Instead of manually copying the updated classes to each project that uses them, create a class library project and reference the compiled file in each project that uses classes. Organizing your classes as this will help you follow the DRY principle (Do Not Repeat Yourself).


If you need to link to files instead of compiled libraries, you can link to the file as a link, so that several projects link to the same file without copying it to each solution folder. To do this, right-click on your project, select "Add an existing item ...", find the .cs file and select "Add as link" from the drop-down list in the lower right corner.

+2
source

Put these base classes in one project and share this project between your various solutions as a class reference library. This way you do not have to copy / paste anything between projects or solutions, and everything should always be relevant.

You can even set up a local NuGet feed so you can use NuGet to retrieve this shared project as a link in a well-structured and manageable way.

+5
source

How about whether you extract classes into a separate project and add a link to that project in every project that you use?

+1
source

It’s a bad idea to copy the folder file throughout the application. To avoid repetition, you can:

  • make a link if the number of files is really small. In the Visual Studio Solution Browser, right-click Add existing file , select your file and click the split button Add as link
  • create a separate project and refer to this project, where necessary, if the number of files is not small.
+1
source

Create a base library and create it in a "shared" location. Add a link to it in the project. This will reduce other projects and be faster to build.

0
source

Source: https://habr.com/ru/post/1382663/


All Articles