Sunday, July 21, 2013

CSharp C# Build XAML- Variables and Arguments - Read and Write quick examples

Introduction:
I found that the working with XAML variables and arguments between the XAML and C# CodeActivity was a bit of a pain so I put together the three most common situations to use as a cheat sheet.

Three examples follows:

CSharp C# Build XAML Variable as an Variable

CSharp  C# TFS Build  example of how to GET and SET an XAML variable


Read/Write XAML visual:
 


Code snippet:

            string subDirectoryForTestRun = @"c:\MySubDirectory";
          
            context.DataContext.GetProperties()["TestSubdirectoryLocation"].SetValue(context.DataContext, subDirectoryForTestRun);
           
           var myVar = context.DataContext.GetProperties().Find("TestSubdirectoryLocation", true);
            var myValue = myVar.GetValue(context.DataContext);
            Console.WriteLine("myValue={0}", myValue);


CSharp C# Build XAML InArgument As InArgument Example






    [Microsoft.TeamFoundation.Build.Client.BuildActivity(Microsoft.TeamFoundation.Build.Client.HostEnvironmentOption.All)]   
    public sealed class LaunchUnattendedTests : CodeActivity<bool>
    {
        public InArgument<IBuildDetail> BuildDetail { get; set; }
        public InArgument<string> TestSeriesManagerLocation { get; set; }
        public InArgument<UnattendedTestInfo> TestTargetInfoParameter { get; set; }
        protected override bool Execute(CodeActivityContext context)
        {
            string TestSeriesManagerLocationNow = context.GetValue(this.TestSeriesManagerLocation);

CSharp C# Build XAML Variable as an InArgument





    [Microsoft.TeamFoundation.Build.Client.BuildActivity(Microsoft.TeamFoundation.Build.Client.HostEnvironmentOption.All)]   
    public sealed class LaunchUnattendedTests : CodeActivity<bool>
    {
        public InArgument<IBuildDetail> BuildDetail { get; set; }
        public InArgument<string> TestSeriesManagerLocation { get; set; }
        public InArgument<UnattendedTestInfo> TestTargetInfoParameter { get; set; }
        protected override bool Execute(CodeActivityContext context)
        {
            IBuildDetail ibd = context.GetValue(this.BuildDetail);
            string BuildOutputPathFull = ibd.DropLocation;





No comments:

Post a Comment