views:

134

answers:

3

Currently I have 4 solutions that are independent projects, however there is quite a bit of duplicated code when it comes to a few areas of the applications.

At the moment it is simply a few forms and their associated code.

When I want to change or improve something, I have to copy and paste to all relevant projects.

I looked at creating a new project within one of the solutions for the .dll/class library, but I felt that this was incorrect. (Please say if I am wrong).

As it is a component for all the applications, I decided to create a new solution for the .dll/class library and am looking at moving the shared code over to that - but, having never gone down this route before, what are my options from here?

Am I able to then include this solution within the others if I need to make a simple change and have it updated in all the projects or instead, should I always be working on the shared component in a separate instance of Visual Studio, outside of the applications using it?

+2  A: 

That's exactly the right way to handle this situation.

You can include projects in multiple solutions by right-clicking the solution and selecting Add Existing Project...

Any changes you then make will appear in all solutions. The only problem this leads to is that it's possible to break one solution from another. This is where automated builds on commit to source control come into their own.

pdr
Thank you for this. - To be clear, I should be creating standalone solutions for shared features, then going to the other solutions and choosing to add project?... The reason I did not like adding a new project directly to an existing solution was because I thought it somehow ties it to that solution and can only be used there - am I wrong?
Wil
You can create a project in an existing solution and add it to others. Then you can add a reference to the project in the projects which already existed.
pdr
@pdr - I can't say I really understood you straight away, but I just tried it anyway (granted only with a shared msgbox - but you have to start somewhere!) and I can't believe how easy and straight forward it was. Many thanks for the help.
Wil
+1  A: 

Moving the common code into a separate shared assembly is an excellent option.

One thing to think about is to keep your common business logic or business object type code separate from UI related code like custom controls - if you need to then have two common assemblies. This is more work initially, but makes things way easier further down the track when you need to make UI changes or change the control suite you are using.

slugster
Many thanks for the help
Wil
+1  A: 
  1. Put shared codes in separate Solution/Project as Class Library,
  2. In post build event of shared projects copy dll's to a specific directory,
  3. Add shared dll's from this directory to other projects/solutions

By doing this each time you build your consumer projects, they will use latest dll's automatically.

afsharm
Many thanks for the help.
Wil