mrk2
mrk2

Reputation: 817

How to add projects into the solution that already in Source Control?

I have two C# projects in TFS and I want to add them to another solution (that is in TFS as well), how to do this correct?

Tried to check out these projects and open the target solution > click "Add" > "existing project" but VS doesn't recognize this projects as they are under Source Control.

All I need now is: 1) Get copies of 2 projects that are already in Source control 2) Add them to my solution 3) Make changes in these projects 4) Check-in changes without affecting the original versions

Upvotes: 2

Views: 2246

Answers (3)

Sharing of code between different solutions is an ati-pattern that should be avoided.

If you have two projects that are required in more than one solution you should build and version them independently.

1) Split the two projects out to a new solution and folder structure. 2) Build and version your two shared assemblies 3) package both assemblies as Nuget packages and store on a network share or ProGet server 4) change the references for your two other solutions to use the new Nuget Package 5) create an automated build to refresh the Nuget package as you change the code.

You then have a shared component that you can make deliberate changes and deploy to your shared location. Each solution that takes a dependency will then notify you when the code is changed.

Upvotes: 1

MichalMa
MichalMa

Reputation: 1230

If you want to have two independent copies of you projects, then Askolein solution is your best bet. However, if you want to reference the same projects from many different solutions then I think the following should work (some of it you listed already):

  • in your workspace map and download directory that contains all projects and location of both solutions. So if you have $/tp1/solution1 for existing solution $/tp1/solution1/proj1 for project and $/tp1/solution2 for new solution then you map $/tp1 and best download all files under it
  • now open solution2 (the one that you want to changes) and click Add->Existing project. You should be able to select projects as they exist on your local disk. You may need to "Add solution to source control" just to add your solution file. However projects are already in TFS and all your operations should not change their content (projects may be in many different solutions)

Good luck!

Upvotes: -1

Askolein
Askolein

Reputation: 3378

Let's call your two projects your framework. You should branch your framework and then link in your new solution to the appropriate branch.

  1. Branch.

In Visual Studio, Team Explorer, browse your code collection

enter image description here

then right click on your framework source root folder and select "branch" . enter image description here

Then checkin your new branch.

  1. Link In your new solution, click "Add Existing project..." and select the projects from the branch you just made.

The branched code basically is a full copy of your framework source code. But this copy is logically linked to the original one (for the TFS system). Nothing will be altered in the original one when you alter the branch, but you can merge selected changeset if you wish.

  1. Folder structure

There are many possibilities about how to structure your TFS collection. My advice is to keep your main developping framework code in a Trunk folder and to have, at the same level, a Branches folder with all the versions in it. In the image above, there is only one branch made yet (named after a released version of my project to do hot fixes if needed, but this is just an example).

  1. Merge

Then, you can merge changes if you want from the branch to the trunk (no obligation, just to avoid manual-error-prone code copy).

The documentation is here.

Upvotes: 1

Related Questions