Deserializing Process Parameters

Team Foundation Build 2010 allows each build process template to expose its own parameters to the build definition editor as well as to the person queuing the build. When using the API it can be confusing to see that these parameters are stored as a string on the IBuildDefinition interface rather than a dictionary or some other data type. These parameters are actually serialized as XAML and stored with the build definition, but there is a helper class in Microsoft.TeamFoundation.Build.Workflow (which typically lives in %ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies) called WorkflowHelpers which has a method called DeserializeProcessParameters which will convert this string into a dictionary of parameter name and the value that’s been specified in the build definition editor.

Here is an example of how to use this:

var tpcUrl = new Uri(args[0]);

var teamProjectName = args[1];

var buildDefinitionName = args[2];

 

var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tpcUrl, new UICredentialsProvider());

var buildServer = tpc.GetService<IBuildServer>();

var buildDefinition = buildServer.GetBuildDefinition(teamProjectName, buildDefinitionName);

var processParameters = WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters);

 

foreach (var parameter in processParameters)

{

Console.WriteLine("Parameter: {0}", parameter.Key);

       Console.WriteLine("\t{0}", parameter.Value);

       Console.WriteLine();

}