Is there an easy way to include a common project easily in other slns?

时间:2016-04-25 09:00:37

标签: c# visual-studio-2012

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)

2 个答案:

答案 0 :(得分: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).

答案 1 :(得分: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.