CONTENTSTART
EXCLUDESTART EXCLUDEEND

Leveraging Visual Studio Online's Team Foundation Server for Kentico

Code repositories are a great tool store changes and allow multiple developers to pull down and work on a project that they did not originally start.  However Visual Studio Online's Team Foundation Studio doesn’t always play nice with Kentico (especially Continual Integration).  Why you may ask?  Well it has to do with the following:

  1. TFS will not include the BIN folder and files by default.  This results in someone having an incomplete set of files when they pull down Kentico from TFS, and unable to run it locally
  2. TFS ignores any file extension with .class or .user.  This equates to any Continuous Integration classes of cms.class and cms.user being completely ignored by default.
  3. TFS includes files like the web.config, which may contain your local connection string, resulting in overwriting other developer’s local connection strings when you push up.
  4. TFS also ignores a lot of the App_Data folder items, this results in a couple resources such as the Smart Search, web analytics, and a handful of others being missing and possibly broken (such as the Smart Search which cannot write a file if the folder is missing)
So after muddling through various stack overflow questions, microsoft articles, and just tinkering, I finally found a way around all of these problems!

Start with Structure Planning

The first thing to discuss before we get into the steps is your repository structure.  There are multiple types of structure models to choose (4 discussed below), but the overarching theme of these is that all but the first method below require a Master folder and Branches folder, which is the recommended structure for when you get into Step 2. 

Note that in the below, Master/Trunk/"Source of Truth" are synonymous.

1: Basic (Trunk Only) - Not Recommended

The first type of repository is that the website is the entire repository.  This is the most basic model.  Anyone who connects to it will be modifying the primary "Source of Truth."  This is not usually recommended unless you have only 1 developer and that’s all that you’ll be handling, and are using it simply as a code-backup.

2: Master and Developer Branch

This model is where you have 2 "sites" within the repository.  The master/trunk, and a development branch.  Any and all developers will pull from the development branch and perform their work.  They must push up and resolve any conflicts with other developers as they push / pull to this development branch.  This is a great method if you have multiple developers working in tangent where you need them to resolve their code together before it goes live.  Then someone who manages the master can pull/merge the changes from Development branch to the Master.

3: Master and Developer Branches

This model is similar to #2, except each developer has their own branch.  This may be more suitable for when developers are working on completely different projects, where you want to be able to sync one project from one developer to master once finished without having ‘pieces’ of the other muddled in.  In this model, once a developer is done and their branch is ready to push to master, the manager can pull/merge the development branch into the master, without affecting the other development branch that's still in progress.

4: Trunk is active development, and branches = feature release

In this model, the master/trunk is where all changes and development occur.  When enough changes are made or a feature is complete, a release is created as a separate branch, which would either be pushed to live or to a QA environment for proofing, and any adjustments needed would remain in that branch AND the master.
 
Which model you choose is up to you, but regardless I would recommend at least creating a "Master" folder and a "Branches" folder in your repository right off the bat, and not set your website folder as the root of the repository.

Step 1: Prepare the environment before connecting to Visual Studio TFS

Download the Files needed for this step.

After downloading the file above, follow these steps:

  1. Unzip the files and merge them into your Kentico site.
  2. In the Web.config, replace the Connection string with the below:
    1. <connectionStrings configSource="web_ConnectionStrings.config"></connectionStrings>
  3. Unzip the web_ConnectionStrings.zip so the web_ConnectionString.config is in the CMS Folder (this is where you store your local connection string)
Note that only the first is truly rqeuired, the web.config replacement in 2 and 3 are to resolve the problem of each developer having different connection strings.

Step 2: Set up a Visual Studio Team Foundation project for the site

I'm not going to outline the steps myself to set up your project, because microsoft has already done this!  Please follow these instructions to set up your tfs project.  Note that it is recommened you create a "Trunk" or "Master" folder, and a "Branches" folder to the project right away.

Step 3: Connect Solution to the Team Foundation Server

Next we need to link the Kentico solution to the Project.  This involves mapping the files and
  1. In Visual Studios, connect to the Visual Studio Team Foundation Server (This may not be needed if you are logged into Visual Studio with your MSDN account and that account is added to the Team Foundation Server).  Go to Team Explorer > Connect on the top > Projects and My Teams > Manage Connections.
  2. In the Source Control Explorer or Team Explorer, you should see your project.  Map/Clone that project/repository to your local folder
  3. Copy your Kentico solution into that new local folder (if you do Trunk/Branches, into the Trunk folder to start out with as this will be the start)
  4. After this is done, open the Kentico solution file (if it’s not already open)
  5. On Solution Explorer, right click on your entire solution, and you should see an “Add to Source Control”, do that.

Step 4: Add missing files

Visual studio excludes a couple of things by default, which really should be included.  One is your BIN files, and the other are empty folders.  Since we are ignoring certain App_Data folders and other items in our .tfignore, we want to add in just the folders required for other users to be able to have a complete Kentico instance.

Note that these steps are a little tricky, but follow along closely and you should be able to get it!

  1. Open up the Visual Studio TF Command Prompt
    1. Use this stack overflow to find the tf.exe location https://stackoverflow.com/questions/6979053/how-to-find-the-path-to-tf-exe-from-msbuild
  2. Copy and Right Click -> Paste into the command prompt each line, one by one, replacing the <YourRoot> with the root location of your install.
    1. tf add "<YourRoot>" /recursive /noignore
    2. tf add "<YourRoot>\CMS\App_Data\CMSTemp"
    3. tf add "<YourRoot>\CMS\App_Data\51Degrees"
    4. tf add "<YourRoot>\CMS\App_Data\Install"
    5. tf add "<YourRoot>\CMS\App_Data\Persistent"
    6. tf add "<YourRoot>\CMS\App_Data\CMSModules\SmartSearch"
    7. tf add "<YourRoot>\CMS\App_Data\CMSModules\CMSInstallation"
    8. tf add "<YourRoot>\CMS\App_Data\CMSModules\HealthMonitoring"
    9. tf add "<YourRoot>\CMS\App_Data\CMSModules\WebAnalytics"
    10. # Now any site-specific media folders, only really necessary if you have initial empty structure folders.
    11. tf add "<YourRoot>\CMS\<YourSiteNameFolder>" /recursive
What the above accomplishes is it adds in the needed folders.  You can manually add them through the Visual Studio Source control explorer, but it's lengthy and hit or miss, this is the quick way to do it.  Failure to do this will mean your Kentico instance will be missing key files and anyone who downloads it to work on it may not have a working instance.

Step 5: Push up your code

Now that the files have been added, the tfignores set, you should be able to go to the Team Explorer tab, go to “Pending Changes” and include any Excluded Changes (check the files though, if the tfignore files are working you should not see any of the excluded content in there).
Check in your changes once included and commit.

Branching

If you wish to create branches of this Kentico instance, follow these steps (Note you must have permission to create branches)
  1. Go to the Team Explorer> Source Control Explorer
  2. Right click on your project -> Branching and Merging -> Convert to Branch
This will convert your project into a branch, in this case your master branch.  Now let’s make a branch of this one.
  1. Right click on the project again and select Branching and Merging > Branch
  2. Create your Target branch name (ex: <theProjectName>_Development)

Conclusion

With many companies requiring repositories for their work, and also for internal projects, it’s vital to be able to get kentico fully uploaded.  With a step by step procedure to follow to make sure your entire instance gets up so the next developer doesn’t have to bang their head on the wall because key files are missing (like bin files). I have no experience in that though, of course….Hope this helped! Happy Kentico-ing!
 
Comments
Blog post currently doesn't have any comments.
= four - nine
CONTENTEND