Working with mDesign and TFS

mDesign keeps most of the information about an application in a combination of it's database/memory/temp folders.

This means that unlike working with regular file based project (e.g. Visual Studio/Powerbuilder/Web site etc) where you can work directly on the files in your TFS local folders, checking out those you need, so you can see what has been modified/added committed.

With mDesign you export your application to a folder, that involves deleting everything already in your folder. If you overwrite the TFS folder you end up checking everything in, so you can't see what has changed in the commit. To avoid this we need to export to a temporary folder then merged the changed/added/deleted files with TFS.

To do this we are using a powershell script based on the one by Sergei Dorogin ( http://techblog.dorogin.com/2011/09/tfs-how-to-sync-server-folder-with.html) to sync a local folder with a TFS folder.

System Requirements
To run this you need a minimum of Powershell v3. To check your version open Powershell and run $PSVersionTable.PSVersion. If the major version is less than 3 download an update from the Microsoft website.

You also need to install Visual Studio Team Foundation Server Power Tools. During the install "Powershell Cmdlets" is not selected by default, make sure you include it. If you do not have Powershell 3 the option will not be present.

When you come the run a Powershell script you may get an error stating "ExportSync.ps1 cannot be loaded because running scripts is disabled on this system"

If this happens open the Powershell console as an Adminstrator and run the following: "set-executionpolicy remotesigned"

The Export Process
There a a number of folder involved in the process - the location of these is not important, but they may need to be set in the configuration files for the scripts. These will be referred to as To get a project from mDesign to TFS the process is:
 * EXPORT_DIR - where the export from mDesign is stored
 * NORMALISED_DIR - where the files that are prepared for commit are
 * TFS_DIR - the local directory where the application is checked out from TFS
 * 1) Export from mDesign Studio to the EXPORT_DIR
 * 2) Run the normalisation scripts which will copy the application to the NORMALISED_DIR
 * 3) Replace the Process Images
 * 4) Sync from NORMALISED_DIR folder to the TFS_DIR
 * 5) Commit

Exporting from mDesign
This is simply a matter of hitting the Export button in mDesign studio, selecting your EXPORT_DIR as the location.

The Normalisation Scripts
The purpose of these is to get the application files into a consistent format before they are committed. When an export is done the order of elements in the XML, closing tags, spacing, etc can vary, even though the underlying process hasn't changed. Also, as some configuration (such as connection strings) are included in the application these can vary from machine to machine. This leads to files being flagged as changed in source control when there isn't really any functional change.

The Normalisation scripts were supplied by CommonTime. Since they use Git as their Source Control system with a BitBucket repository the scripts make some references to these, but they are actually not Source Control system dependent.

The scripts take the contents of the EXPORT_DIR, perform the necessary changes and output it to the NORMALISED_DIR.

These are configured in the [ExportToolsDir]\setup\ExportSettings.bat file: The entry point for this script is ExportApp.bat
 * EXPORT_DIR = exportPath
 * NORMALISED_DIR = gitPath
 * TFS_DIR = tfsPath

Replace the Process Images
Each Process has an icon in mDesign. We can upload our own one through mDesign studio, but after an export they sometimes seem to return to the default mDesign Icon. So we have a Powershell script that replaces the image for each process with our logo.

Sync to the TFS Directory
TFS doesn't automatically change the status of files when they are updated outside of a TFS based editor (such as Visual Studio).

Our sync powershell script removes everything in the local copy TFS checkout of the application (in TFS_DIR) and replaces it with the content of the NORMALISED_DIR. This updates the files but doesn't update the status.

The script first checks for any files that are not in TFS but are in the local TFS_DIR. For any of these it sets an Add status

It then loops through all the files that are in TFS, if they are not in the local TFS_DIR is sets the status to Delete, otherwise it sets it the Edit.

This basically does they work, except for it leaves all files that aren't being Added or Deleted with an Edit status.

To finish off we run the "tfpt uu" (Undo Unchanged) command. This resets the status on any files which are identical in TFS and TFS_DIR

Committing
This is done the normal way (i.e. through Visual Studio or the Explorer context menu (if you have powertools shell integration)

The scripts to drive the process
The scripts for this process are committed into TFS at $/Unity Mental health/Mobile/mDesignUtilities

The complete process (other than Committing) can be done by running "export_to_tfs.bat"