Azure DevOps Services |Azure DevOps Server |Azure DevOps Server 2022
在此示例中,我们将操作添加到工作项查询中心的查询上下文菜单。
提示
有关最新的扩展开发指南,包括主题处理以及从 VSS.SDK 的迁移,请参阅 Azure DevOps 扩展 SDK 开发人员门户。
先决条件
更新扩展清单
将您的动作添加到 扩展清单的贡献部分。
...
"contributions": [
{
"id": "myAction",
"type": "ms.vss-web.action",
"description": "Run in Hello hub action",
"targets": [
"ms.vss-work-web.work-item-query-menu"
],
"properties": {
"text": "Run in Hello hub",
"title": "Run in Hello hub",
"icon": "images/icon.png",
"groupId": "actions",
"uri": "action.html"
}
}
]
...
属性
| 财产 | 描述 |
|---|---|
| 文本消息 | 显示在菜单项上的文本。 |
| 标题 | 显示在菜单项上的工具提示文本。 |
| 图标 | 显示在菜单项上的图标的 URL。 相对 URL 将使用 baseUri 进行解析。 |
| groupId | 确定此菜单项相对于其他菜单项的显示位置。 |
| uri | 注册菜单操作处理程序的页面的 URI(请参阅下文)。 |
| registeredObjectId | (可选)已注册菜单操作处理程序的名称。 默认为参与者 ID。 |
了解可以在 扩展点中添加操作的所有位置。
您的 HTML 页面
菜单操作由嵌入 HTML 文件中的 JavaScript 脚本表示。 将以下内容保存在与扩展清单文件中引用匹配的文件和位置中。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Action Sample</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
<script>
window.requirejs.config({
enforceDefine: true,
paths: {
'SDK': './lib/SDK.min'
}
});
window.requirejs(['SDK'], function (SDK) {
SDK.init();
SDK.ready().then(() => {
// Register the menu action handler
SDK.register(SDK.getContributionId(), {
execute: function (actionContext) {
alert("Hello, world");
}
});
});
});
</script>
</head>
<body>
<div>
The end user doesn't see the content on this page.
It runs in the background to handle the contributed menu item being selected.
</div>
</body>
</html>
提示
有关详细信息,请参阅 扩展点、菜单和工具栏、贡献模型公式设计系统、REST API 参考、扩展示例以及 开发人员社区中的资源。
后续步骤
打包、发布和安装扩展。