February 20, 2014

Automation Build Process for SharePoint with TFS 2013

If you are working in a “SharePoint Farm Application” project, you may are nagging about the publishing process after each changing the code or adding a new function. You have to know all about map folders, copy and paste different kinds of files or scripts to the target folders, and in the worst case, registering many DLLs inside Global Assembly Cache(GAC) manually. TFS Build and it’s workflow helps us to overcome this difficulties so all team members seems be happy just by clicking Publish Button, then everything is going to be published on the SharePoint Server.

In this blog I will not cover the whole configuration of TFS build from the scratch. In the TFS Build chapters from Pro Team Foundation (Apress Ebook), you can learn how TFS Build is working and what steps you need to do for running this service.

Download TFS Build Chapters.

After installing and configuring TFS Build Service, it is time to create a new Build Definition. Following you can see the very important parts of configuring this file that I have done to publish our sharepoint project to target server.

1-In the “Build Defaults” section, try to select this option: Copy Build Output to the server

2- Inside the “Process” section and below the “Advance” option, configure this switch:

MS Build arguments: /p:IsPackaging=true

3- By configuring all other sections of Build Definition files, the TFS Build is going to get the latest version of code and build it and then copy in the target folder. Right now it is turn to copying files to sharepoint folders and also registering DLLs.

There are two general approaches for doing this step.
1- using TFS Build Definition(embedded command)
2- writing script and running it at the end of publishing process.

And also you can use the mix scenario as I did in my solution.

Actually I did copy and paste all files to target folders using TFS Build Definition workflow and after that, by running script file at the end of workflow publishing, all the DLLs have been registering properly on the target servers.

3-1) to copy and paste all files to sharepoint folder you can use CopyDirectory activity inside the TFS workflow. I should mention that for the Destination and Source, I entered the hardcode paths.

3-2) For registering DLLs I have done as you can read below:

I created a script file named: RegisterDlls&CopyFiles.ps1

I put the gacutil.exe in the root drive of target server for registering the Dlls.

This line should be written inside the script file:     C:gacutil.exe -u SampleProject.dll

4- For the final step, in the TFS Build Definition set this configuration:

Post-Build script path:  "the TFS path of script"

By implementing and running this simple steps you will be able to publish sharepoint project via TFS Build and enjoy it’s facilities. Right now you need a best strategy to manage your branches and the target server.
Which branch should be published on which server?
TFS Build with Branching Strategy

You can download and see my strategy regarding with collaboration between different branches to different servers in a sharepoint project in this PowerPointTFS Build file.

To understand about my Branching strategy just try to read this blog as well.