Microsoft.TeamFoundation.WorkItemTracking.Client.Field添加默认值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Microsoft.TeamFoundation.WorkItemTracking.Client.Field添加默认值相关的知识,希望对你有一定的参考价值。

尝试向缺陷添加默认值。

var x = Defect.Validate();
if (x.Count != 0)

foreach (Microsoft.TeamFoundation.WorkItemTracking.Client.Field item in x)

Defect[item.Name] = item.AllowedValues.Count==0?"test": item.AllowedValues[0];


添加此内容不会提供帮助!是另一种方式。

答案

您可以检查下面的REST API,将字段添加到工作项类型:

POST https://instance/collection/_apis/work/processes/processId/workItemTypes/witRefName/fields?api-version=5.0-preview.2

这里有一些代码示例可以帮助您:

https://github.com/microsoft/azure-devops-dotnet-samples/blob/master/ClientLibrary/Samples/WorkItemTrackingProcess/ProcessesSample.cs#L426

       public ProcessWorkItemTypeField Field_AddFieldToWorkItemType()
        
            ProcessWorkItemTypeField processWorkItemTypeField = null;
            System.Guid processId = Context.GetValue<Guid>("$processId");

            VssConnection connection = Context.Connection;
            WorkItemTrackingProcessHttpClient client = connection.GetClient<WorkItemTrackingProcessHttpClient>();

            //get the list of fields on the work item item
            Console.Write("Loading list of fields on the work item and checking to see if field '0' already exists...", _fieldRefName);

            List<ProcessWorkItemTypeField> list = client.GetAllWorkItemTypeFieldsAsync(processId, _witRefName).Result;

            //check to see if the field already exists on the work item
            processWorkItemTypeField = list.Find(x => x.ReferenceName == _fieldRefName);

            //field is already on the work item, so just return it
            if (processWorkItemTypeField != null)
            
                Console.WriteLine("field found");
                return processWorkItemTypeField;
            
            else
            
                //the field is not on the work item, so we best add it
                Console.WriteLine("field not found");
                Console.Write("Adding field to work item...");

                AddProcessWorkItemTypeFieldRequest fieldRequest = new AddProcessWorkItemTypeFieldRequest()
                
                    AllowGroups = false,
                    DefaultValue = String.Empty,
                    ReadOnly = false,
                    ReferenceName = _fieldRefName,
                    Required = false
                ;

                processWorkItemTypeField = client.AddFieldToWorkItemTypeAsync(fieldRequest, processId, _witRefName).Result;

                Console.WriteLine("done");

                return processWorkItemTypeField;
            
        

以上是关于Microsoft.TeamFoundation.WorkItemTracking.Client.Field添加默认值的主要内容,如果未能解决你的问题,请参考以下文章

Microsoft.TeamFoundation.WorkItemTracking.Client.VerbatimMessageException 未处理

Azure DevOps 发布错误“Microsoft.TeamFoundation.DistributedTask.Pipelines.PipelineValidationException(类型

Microsoft.TeamFoundation.WorkItemTracking.Client.Field添加默认值

如何从 Microsoft.TeamFoundation.WorkItemTracking.Client 访问 git 提交的消息?

Powershell Get-TfsWorkspace 找不到作为另一个用户创建的工作区。 (Microsoft.TeamFoundation.PowerShell)

如何解决这个问题?,您是不是缺少程序集参考