How to build your Sitefinity solution with TFS/VSTS

Recently I started working on a new project using Sitefinity. Sitefinity is one of the best .NET CMS systems you can find out there, but it comes with tricks. The first one I had to deal with was how to put it under TFS/VSTS Build.

As you probably know, you need to use Sitefinity Project Manager to create a new Web app. This tool gives you a good head start and you can have a new website up and running in a matter of seconds. What I don’t like about that tool is that all binaries are copied directly in the bin folder, which makes things a bit ugly, especially because the dependencies take about 300MB of space. Ideally you would use NuGet for this.

Wait a second…I had to install Sitefinity on my workstation. Are you saying that I can remove the binaries and use NuGet packages instead?

Yep. Let me show you how.

NuGet Feed

Telerik Progress provides a Sitefinty NuGet feed which contains all packages you need to run Sitefinty:

http://nuget.sitefinity.com/nuget

The easiest way to set it up is to reference Telerik.Sitefinity.All package:Sitefinity_NuGetPackage

NuGet Configuration

Now that you found the package and added it to the solution, you need to create a NuGet.config file with the following definition. You will need to provide path to this file in the NuGet restore task, otherwise TFS/VSTS Build agent won’t be able to restore NuGet Packages and your build will fail.

XML Transformations

Bear in mind that Sitefinity by default stores connection string in DataConfig.config file. You will probaby want to add a new file e.g. DataConfig.Deploy.config for later transformation.

I used a PowerShell script to transform the file.

NOTE: PowerShell script relies on the Microsoft.Web.XmlTransform.dll file which was extracted from a Microsoft.Web.Xdt NuGet package and put in the same folder as the transformation script.

NOTE 2: TransformXml.ps1 requires SourceFile nad TargetFile. While this might not be self-explanatory, the script will run the transformation and apply it over the source file. Feel free to modify this as you like.

EDIT: It is recommended to use a Marketplace task for config transformations
https://marketplace.visualstudio.com/items?itemName=qetza.xdttransform

Build Definition

This isn’t any different that before. You need fhe following steps

  1. Restore NuGet packages
  2. Transform DataConfig.config file (optional)

    -SourceFile $(build.sourcesdirectory)\SitefinityWebApp\App_Data\Sitefinity\Configuration\DataConfig.config -TargetFile $(build.sourcesdirectory)\SitefinityWebApp\App_Data\Sitefinity\Configuration\DataConfig.Deploy.config
  3. Build the solutionSitefinity_Build_3
    Optional: Pass the following parameters to MSBuild arguments if you want to produce a Web Deploy FileSystem package
    /p:DeployOnBuild=true;DeployTarget=PipelinePreDeployCopyAllFilesToOneFolder;PackageTempRootDir="$(Build.StagingDirectory)"
  4. Run the tests (optional)
  5. Publish Artifact

And that’s it. Let me know if you need any help.

Share this:

Leave A Reply

Your email address will not be published. Required fields are marked *