通过工作项类型定义 xml 在工作项窗体中添加扩展

Azure DevOps Services | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018

可以使用工具将工作项类型导出为 xml witadmin ,其中包括工作项窗体的布局。 作为本示例的一部分,我们将页面、组和控制贡献添加到布局。 我们还将控件添加到敏捷“用户情景”工作项类型。 有关详细信息,请参阅 WebLayout xml

注意

仅Azure DevOps Server(而不是Azure DevOps Services)才支持通过 xml 进行的工作项表单自定义。

在工作项窗体中添加扩展

  1. 在 Azure DevOps Server 中安装工作项表单扩展。

  2. 打开 Developer Command Prompt。 使用以下命令将 xml 文件导出到桌面。

    witadmin exportwitd /collection:CollectionURL /p:Project /n:TypeName /f:FileName
    

    文件在指定的目录中创建。

  3. 在此文件中,转到 “WebLayout ”部分。 在 WebLayout 部分内,注释 blob 指定哪些扩展面向集合的工作项表单。 对于每个扩展,其所有表单贡献都列在 ID 和输入 ((如果它是控制贡献) )。 在以下示例中,注释显示集合上安装 的颜色控制开发 扩展。 该扩展具有一个控制贡献,需要两个输入。

         <!--**********************************Work Item Extensions***************************
    
     Extension:
         Name: color-control-dev
         Id: example.color-control-dev
    
         Control contribution:
             Id: example.color-control-dev.color-control-contribution
             Description:
             Inputs:
                 Id: FieldName
                 Description: The field associated with the control.
                 Type: Field
                 IsRequired: true
    
                 Id: Colors
                 Descriptions: The colors that match the values in the control.
                 Type: String
                 IsRequired: false
    
  4. “工作项扩展 ”部分中查找扩展 ID:

         <!--**********************************Work Item Extensions*************************** 
    
     Extension:
         Name: color-control-dev
         Id: example.color-control-dev
         ...
    
  5. “工作项扩展 ”部分下面添加扩展标记,如下所示,使扩展可供工作项窗体使用。 若要在窗体中放置贡献,必须在节中 Extensions 指定其扩展。

         <!--**********************************Work Item Extensions***************************
         ...
    
         Note: For more information on work item extensions use the following topic:
         https://go.microsoft.com/fwlink/?LinkId=816513
         -->
    
         <Extensions>
             <Extension Id="example.color-control-dev" />
         </Extensions>
    
  6. 在 xml 中指定扩展会自动将窗体内扩展中定义的 页面 贡献放在该窗体中的扩展中。 可以在以下示例中移动贡献。

添加页面贡献

    <Page Id="Details">
    <PageContribution Id="<page contribution id>" />
    ...       

添加组贡献

    <Page Id="Details">
    ...
        <Section>
        ...
            <GroupContribution Id="<group contribution id>" />
            ...

页面贡献和组贡献不能采用任何其他布局元素。

添加控件贡献

页面 贡献不同,指定 xml 中的扩展不会自动放置 控件 贡献。 若要在窗体中添加这些贡献,请在窗体中添加具有贡献标记。 以下示例将 ControlContribution 添加到 规划 组。

如果控件贡献定义了任何必需的输入,则用户必须为该输入提供值。 对于任何非必需的输入,用户可以决定是否将值设置为输入。 在以下示例中,设置 FieldNameColors 输入。

    <Page Id="Details">
    ...
        <Section>
        ...
            <Group Id="Planning">
            ...
                <ControlContribution Label="Priority" Id="example.color-control-dev.color-control-contribution">
                    <Inputs>
                        <Input Id="FieldName" Value="Microsoft.Azure DevOps Services.Common.Priority" />
                        <Input Id="Colors" Value="red;green" />
                    </Inputs>
                </ControlContribution>

                <Control Label="Risk" Type="FieldControl" FieldName="Microsoft.Azure DevOps Services.Common.Risk" />
  1. 使用 witadmin. 导入此 xml 文件。

    witadmin importwitd /collection:CollectionURL /p:Project /f:FileName

扩展是通过工作项表单配置的!