locked
How to reuse your custom code activities from the XAML build templates in the new build definitions RRS feed

  • Question

  • I thought it is important to tell others how we have been able to reuse our custom code activities. As you are aware, in the XAML build template, you would create a custom library solution with two projects. One for the code activities and one for all your templates. Then you tell the build controller the "Version control path to custom assemblies". Well, this is how I set it up and it worked. In the new build definition I wanted some of the same custom actions so what we did was create a console app. We added each code activity as a method and separated them into classes under the same name space. The console app will get passed in the name of the method to call so we setup a switch in program.cs to handle it. The variables are then passed in as parameters.  The console app was compiled and the bin\release folder copied to a folder on the build controller.  To add a call to one of the CA's from the build template just add a command line build step.  The "Tool" is the full path to the console app.  The first argument is the build operation variable and its value is the method name.

    Tool = E:\Builds\_BuildCustomActivities\DMACustomBuildActivities.exe

    Arguments = SNC_BuildOperation="InitializeVariables"

    namespace DMACustomBuildActivities

    {

    class Program

    {

    static void Mail(string[] args)

    {

    #region Cycle through parameter list and assign accordingly foreach (string argument in args) { string[] arrArgument = argument.Split('='); switch (arrArgument[0]) { case "SNC_BuildOperation": var buildOperation = arrArgument[1]; BuildOperation = (BuildOperation)Enum.Parse(typeof(BuildOperation), buildOperation); break; } Console.WriteLine("parameter: {0}", argument); } #region Initialize Variables into Environment target User if (BuildOperation == DMACustomBuildActivities.BuildOperation.InitializeVariables) { SNCBuildUtilities.LogMessage("Program", "About to InitializeVariables"); foreach (string snc_variable in SNCVariables) { new SNCBuildUtilities().MakeUserVariable(snc_variable, Environment.GetEnvironmentVariable(snc_variable, EnvironmentVariableTarget.Process)); } }

    }

    }

    public enum BuildOperation

    {

    SendEmail,

    InitializeVariables,

    WorkItemStatus,

    ChangeEnvVarValue,

    MakeUserVariable

    }

    }


    Unfortunately in c#, you can't just change a variable value that is in EnvironmentVariableTarget.Process and have it persist from one build step to the next using my method.  What I did was to create an initial build step that calls a method which takes the variables from Process and creates them in User.  After that, you can change them all you want and it will persist between build steps.  I am still working to find a way to change process variables but for the time being this is working.

    I am sure others will find a way to do the same task in a better way than how we implemented it but for those wondering how to reuse their code, this is one option.  Best of luck.

    Thursday, June 8, 2017 12:22 PM

All replies

  • Thanks for the suggestion. Appreciate your effort.


    Friday, June 9, 2017 2:54 AM