How to Share Code

- J.D. Meier, Jason Taylor, Alex Mackman, Prashant Bansode

If you have source code that is used by multiple team projects, you can either manage the source code within the team project of the owning team or create a team project specifically for the shared source code.

Teams consuming shared source code have the following two options:
  1. Reference the code from a shared location.
  2. Branch the shared code.

1. Reference the code from a shared location.
In this case, the projects consuming the shared code can simply map the source from the shared location into their workspaces on the client machine. This creates a configuration that unifies the source from the shared location with the projects on the client-side.

The advantage of this approach is that changes to shared source are picked up every time the latest source is retrieved into the workspace. For example, consider that you have two team projects named Client and Shared Code, where Shared Code is the location of the shared source. To reference the code from a shared location, these projects will share a common path on the client’s hard drive as shown below:
  • c:\TestProject\Client
  • c:\TestProject\Shared Code
Both projects will have workspace mappings to those local hard drive paths.
Source control folder Local folder
$/Client c:\TestProject\Client
$/Shared Code c:\TestProject\Shared Code

For more information, see “Working with multiple team projects in Team Build” at http://blogs.msdn.com/manishagarwal/archive/2005/12/22/506635.aspx

2. Branch the shared code.
In this case, the projects consuming the shared code can branch the source from the shared location into their respective team projects. This creates a configuration that unifies the source from the shared location with the projects on the server-side.

The difference is that changes to the shared source are picked up as part of a merge process between the branches. This makes the decision to pick up changes in the shared source much more explicit.

For example, consider that you have two team projects named Client and Shared Code, where Shared Code is the location of the shared source. Use the following steps to branch the code from the shared location:
  1. In Source Control Explorer, right-click the root folder of Shared Code.
  2. Select the Branch option.
  3. In the Branch dialog box, set the Target to the root folder of the Client team project, and then click OK.
  4. After the branch operation completes, do not forget to check in the branched source code.

Additional Resources

Last edited Jul 31, 2007 at 2:08 PM by prashantbansode, version 9

Comments

RichardBerg May 3, 2007 at 8:26 PM 
With #1, make sure the relative paths stay constant. Otherwise other people's builds will fail unless they duplicate your workspace mappings exactly.