, , , , , , , ,

I apologize for missing a post last week.  The combination of a new home and a very busy work week, destroyed any possibility of getting a post out.  The Sync-AXTFSWorkingFolder function is one of 2 Team Foundation Server functions that I have for getting AX code.  This one is a lot less versatile than my other one but it is much more practical for a build process because it is light years faster.  We will explore my other function in a later post.

This function requires a little setup in your PowerShell profile.  The function needs to know the location of TF.exe and I handle this by adding it to the $env:path variable in my PowerShell profile.  There are many ways to solve this problem, this is just the one I’ve chosen.  TF.exe is available when you install Team Explorer for Visual Studio.  You should match your version of Team Explorer to the version of TFS that you are using.

The Sync-AXTFSWorkingFolder function takes between 1 and 6 parameters:

  • WorkingFolder (The working folder to sync from TFS)
  • Label (This value is used if you want to sync a label version instead of the current version)
  • SetLabel (Switch parameter that will allow you to label the current version if a unique Label parameter is passed with it)
  • LabelScope (Allows you to restrict the scope of the label in case there are multiple locations with the same label)
  • Comment (Allows you to set a comment on the label)
  • VariablePath (Path to a file used to default the parameters/variables)

This function can be found in Codeplex.  The steps of this function are:

  • Load the variables if a VariablePath parameter is used
  • Determine if a label was passed in
  • If so, set up the version and Label/LabelScope
  • Determine if the label exists in TFS
  • If so, sync the working folder with the label version
  • If not, get the current version and determine if the label needs to be set in TFS and set it
  • If no label is passed, sync the working folder with the current version
  • Send the success/fail message

This function assumes certain things.  It assumes that Visual Studio is installed with Team Explorer on the local computer.  It assumes that the user running the function has the working folder set up on the computer that the function is being run on.  It assumes that the user has permissions to read and set labels in TFS.  Lastly, it assumes that the path to TF.exe is known.  I also only run this function on my DevBuild server.  While this server has Team Explorer installed and configured with a working folder, my DevBuild AX environment is not connected to TFS.  Because of how AX natively works with TFS, I would not recommend running this function on a working folder that is used by AX as it could cause your AX instance to become out of sync with TFS.