-2

I'm currently working on a redesign of multiple different projects. One thing I noticed is 2 sub projects that are included in their own versions in each and every of the main projects. These sub projects are in essence nothing more than projects that get compiled into dlls.

Now I know that I could extract them and compile them and then include the dll into the appropriate projects where they are used. The only problem with this method is that if the source code of those sub projects changes and thus the dlls I would have to manually copy them into each and every main project. As it has to be done manually this means in essence that I could overlook to update it for single projects which is not ideal.

So I'm wondering now if there is any easy way to handle this so that I can update these sub projects (or extracted projects) and then automatically have the updated version available for each of the main projects when they get compiled?

(To make it a bit clearer I'm wondering if there is some Visual studion solution there that allows to link these extracted projects in a way so that I automatically always use the latest version of them in my main projects)

Thomas
  • 2,886
  • 3
  • 34
  • 78
  • And as always if there is a - it would be good to know why as that can help improve future questions and also current questions. ;) – Thomas Apr 25 '16 at 19:31
  • Voted -1 for wanting to "include a project in other slns" but not having tried including the project in the sln based on a wrong hazy memory. After that the question is a dup of http://stackoverflow.com/questions/29979125/impact-of-adding-dll-reference-vs-project-reference – zeromus Apr 27 '16 at 00:16
  • @zeromus First off I did not know what way exists at all so not trying does not count there at all. Second if you refer my COMMENT in regards to the one answer you may notice that I said in answer to your "try" thing that I asked the COMMENT (not the question) because I did not have a chance to try it out at all for at least a full day and wanted to know if I'm understanding things right. That aside if the other question leads to the same answer as for this question and this question is thus a duplicate you should vote to close this question here with the refrence to the other one. – Thomas Apr 27 '16 at 00:32

2 Answers2

2

You can easily reference same project in multiple solutions. Right click on solution -> Add Existing Project... and select your project. In other project you can easily add reference to your core project by right clicking on project, selecting Add Reference and then selecting project instead of dll. Any changes to core project will reflect in every solution that references it (and its dlls).

Nino
  • 6,931
  • 2
  • 27
  • 42
  • I always thought that "add existing project" does make a copy instead of adding it as a reference or am I wrong there? As for add reference do I get it right that I don't need to add the "core" project to the solution and "just" need to add reference to the core project inside my main projects each? (that sounds like the way to go then there) – Thomas Apr 25 '16 at 09:25
  • You can only add reference to a project that's inside the solution. So, you have to add existing project that needs to be referenced to solution. You can easily try all the scenarios with two solutions and three projects. In one solution create new windows forms application project as main project. Then create new class library project to solution. In your winforms application add reference to class library project. Now make another solution with winforms project and add _existing_ project (the class lib one created in first solution) and add reference to it. I hope this clears things for you. – Nino Apr 25 '16 at 10:32
  • Why do you have to guess if it makes a copy? Try it and then inspect your disk and the contents of csprojs and slns. – zeromus Apr 25 '16 at 10:37
  • @zeromus I just wasn't sure if my memory of me doing something similar once and creating a copy with that was erronous or not and as for testing I only have time in a few hours to test and see what I can ask in 30 seconds here in the comments and maybe get answered in case the poser sees it. – Thomas Apr 25 '16 at 12:13
2

Yes you can add a common project to more than one solutions easily. Follow the steps: RightClick on Solution > Add > Existing Project... will let you add projects to your current solution. . This lets you include the same project in multiple solutions.

Then you can add a reference to the common code from other projects by adding a project reference to that class library. The advantage of having a project reference as opposed to a binary/assembly reference is that if you change your build configuration to debug, release, custom, etc, the common class library project will be built based on that configuration as well.

error_handler
  • 1,191
  • 11
  • 19