Partager via


How to: Sync files in different team projects when one of them is changed?

Here’s an interesting scenario, there are several files in several team projects that need to match after any of them was changed. There’s a way to do that, but it's not so direct, you'll need to write some code:

  • Establish a merge relationship between the files if you haven't already
  • Create a windows service project and run it under an account that has permission to the files
  • In the service's code, connect to the server, instantiate a VersionControlServer object, and register the service to the CommitCheckin event in VersionControlServer class
  • Loop through CommitCheckinEventArgs.Changes and check if any of the files was changed and that the merge flag is not set in the change type, then merge the change over to the other files

Note that when you have to exclude changes that have the merge flag set because otherwise you'll end up with an infinite loop when you check in from the CommitCheckin event handler. You need a stopping condition (when changeType doesn't include merge).