Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tfs 在构建期间写入ProcessParameters_Tfs_Build_Workflow Foundation 4 - Fatal编程技术网

Tfs 在构建期间写入ProcessParameters

Tfs 在构建期间写入ProcessParameters,tfs,build,workflow-foundation-4,Tfs,Build,Workflow Foundation 4,我的TFS2012自定义生成工作流有许多自定义参数,这些参数在我的生成定义中定义。我想将它们全部传递给在构建期间运行的exe(我知道自定义活动的选项,但我不能使用它,因为我不想每次都更改控制器的二进制文件) 我设法将buildDetail.ProcessParameters和buildDetail.buildDefinition.ProcessParameters写入文件并传递给我的exe,exe将解析它们(可能使用)。然而,这意味着exe将需要合并这两个ProcessParameters,我希

我的TFS2012自定义生成工作流有许多自定义参数,这些参数在我的生成定义中定义。我想将它们全部传递给在构建期间运行的exe(我知道自定义活动的选项,但我不能使用它,因为我不想每次都更改控制器的二进制文件)

我设法将
buildDetail.ProcessParameters
buildDetail.buildDefinition.ProcessParameters
写入文件并传递给我的exe,exe将解析它们(可能使用)。然而,这意味着exe将需要合并这两个
ProcessParameters
,我希望避免这种情况


是否有任何方法可以从工作流中获取结果ProcessParameters?我可以调用,但如何获取工作流的根活动?

我通过保留
WorkflowInstanceProxy来实现这一点,建议如下:

公共类WriteProcess参数:CodeActivity
{
受保护的覆盖无效执行(CodeActivityContext上下文)
{
WorkflowInstanceProxy=context.GetExtension().GetProxy();
活动根=proxy.WorkflowDefinition;
Dictionary processParams=WorkflowHelpers.GetProcessParameters(根);
//以某种方式序列化processParams。。。
}
受保护的覆盖无效缓存元数据(CodeActivityMetadata元数据)
{
base.CacheMetadata(元数据);
metadata.AddDefaultExtensionProvider(()=>newworkflowInstanceInfo());
}
私有类WorkflowInstanceInfo:IWorkflowInstanceExtension
{
私有工作流InstanceProxy m_代理;
public IEnumerable GetAdditionalExtensions(){yield break;}
public void SetInstance(WorkflowInstanceProxy实例){this.m_proxy=instance;}
public WorkflowInstanceProxy GetProxy(){return m_proxy;}
}
}
这在我的玩具测试中起作用,但在实际的工作流程中不起作用(不确定为什么)。因此我最终阅读了属性,如下所示:

public InArgument<string> Filename { get; set; }

protected override void Execute(CodeActivityContext context)
{
    var propDescriptors = context.DataContext.GetProperties().Cast<PropertyDescriptor>();
    var props = new Dictionary<string, object>();
    foreach (var propDesc in propDescriptors.OrderBy(p => p.Name))
    {
        object value = propDesc.GetValue(context.DataContext);
        if (value == null)
        {
            var converter = TypeDescriptor.GetConverter(propDesc.PropertyType);
            if (converter.CanConvertTo(propDesc.PropertyType))
            {
                value = converter.ConvertTo(value, propDesc.PropertyType); // Known case: null string
            }
            else
            {
                continue;  // Known case: RunTestParameters
            }
        }
        else
        {
            if (!value.GetType().IsVisible || !value.GetType().IsSerializable)
            {
                continue;
            }
        }

        props.Add(propDesc.Name, value);
    }

    File.WriteAllText(Filename.Get(context), WorkflowHelpers.SerializeProcessParameters(props));
}
publicinargument文件名{get;set;}
受保护的覆盖无效执行(CodeActivityContext上下文)
{
var propdescriptor=context.DataContext.GetProperties().Cast();
var props=newdictionary();
foreach(propdescriptor.OrderBy(p=>p.Name)中的var propDesc)
{
对象值=propDesc.GetValue(context.DataContext);
如果(值==null)
{
var converter=TypeDescriptor.GetConverter(propDesc.PropertyType);
if(converter.CanConvertTo(propDesc.PropertyType))
{
value=converter.ConvertTo(value,propDesc.PropertyType);//已知大小写:null字符串
}
其他的
{
continue;//已知情况:RunTestParameters
}
}
其他的
{
如果(!value.GetType().IsVisible | |!value.GetType().IsSerializable)
{
持续
}
}
props.Add(propDesc.Name,value);
}
WriteAllText(Filename.Get(context),WorkflowHelpers.SerializeProcessParameters(props));
}
public InArgument<string> Filename { get; set; }

protected override void Execute(CodeActivityContext context)
{
    var propDescriptors = context.DataContext.GetProperties().Cast<PropertyDescriptor>();
    var props = new Dictionary<string, object>();
    foreach (var propDesc in propDescriptors.OrderBy(p => p.Name))
    {
        object value = propDesc.GetValue(context.DataContext);
        if (value == null)
        {
            var converter = TypeDescriptor.GetConverter(propDesc.PropertyType);
            if (converter.CanConvertTo(propDesc.PropertyType))
            {
                value = converter.ConvertTo(value, propDesc.PropertyType); // Known case: null string
            }
            else
            {
                continue;  // Known case: RunTestParameters
            }
        }
        else
        {
            if (!value.GetType().IsVisible || !value.GetType().IsSerializable)
            {
                continue;
            }
        }

        props.Add(propDesc.Name, value);
    }

    File.WriteAllText(Filename.Get(context), WorkflowHelpers.SerializeProcessParameters(props));
}