Got a build definition template, with custom argument 'NpmEnabled' (if i look at the xml of the xaml template, it is a part of the
<x:Members>
<x:Property Name="NpmEnabled" Type="InArgument(x:Boolean)" />
</x:Members>
I can set the NpmEnable in my Build Definition.
Now i have a CustomActivity, and want to use this setting. How do I get this setting from the context?
The next code does not work...
[BuildActivity(HostEnvironmentOption.All)]
[ActivityTracking(ActivityTrackingOption.ActivityOnly)]
public sealed class NpmInstall : CodeActivity
{
public InArgument<string> NpmEnabled { get; set; }
public override void Execute(CodeActivityContext contect)
{
string x = context.GetValue<string>(this.NpmEnabled);
}
}
This way i need to set the NpmEnabled variable in the workflow template to a specific value, but i want the value of the setting I see in the build definition.
It is very easy: in your custom template, you will refer to the assembly containing your custom activity at the beginning of the build template
<Activity xmlns:myns="clr-namespace:MyCompany.TfsBuild.Activities;assembly=MyCompany.TfsBuild.Activities"
and then invoke the activity like this
<myns:NpmInstall NpmEnabled="[NpmEnabled]" />
the square parenthesis introduce a VB expression.
Everything is done in the XAML.
Please, fix the incoherence in your code: the
NpmEnabled
variable is declared asBoolean
, while the Activity property is of typestring
.