在任何消息通道上都找不到处理程序



我是一个彻头彻尾的菜鸟,一直在尝试将 VSTS 工作项字段值放入我的 VSTS 扩展中,并且遇到了一个问题。每当我在浏览器中加载扩展程序时,都会收到以下错误消息:

No handler found on any channel for message: {"id":2,"methodName":null,"instanceId":"sample-extension-page","instanceContext":{[RETRACTED]},"params":null,"jsonrpc":"2.0"}

我已经搜索了互联网,但无法找到我的问题是什么。我只想传入 System.Id 和 System.Title 的活动工作项字段值,以便我可以在扩展页/窗体上显示它们。任何帮助将不胜感激,谢谢!

我的 html 页面中的脚本:

<script type="text/javascript">
console.log("VSS Initialize...");
VSS.init({
usePlatformScripts: true,
explicitNotifyLoaded: true,
usePlatformStyles: true,
configureModuleLoader:true
});
console.log("VSS Ready.");
VSS.ready(function(){
console.log("VSS REQUIRE");
VSS.require(["TFS/WorkItemTracking/Services"], function(_WorkItemServices) {
console.log("Inside VSS REQUIRE.");
// Get the WorkItemFormService.  This service allows you to get/set fields/links on the 'active' work item (the work item
// that currently is displayed in the UI).
console.log("GET WORK ITEM FORM SERVICE");
function getWorkItemFormService(){
console.log("Inside GET WORK ITEM FORM SERVICE!");
return _WorkItemServices.WorkItemFormService.getService();
}
// VSS.register(VSS.getContribution().id, function(){
console.log("VSS REGISTER.");
console.log("VSS Contribution ID === " + VSS.getContribution().id);
VSS.register(VSS.getContribution().id, function(){
console.log("Inside VSS REGISTER");
return {
// Called when the active work item is modified
onFieldChanged: function(args) {
$(".events").append($("<div/>").text("onFieldChanged - " + JSON.stringify(args)));
},
// Called when a new work item is being loaded in the UI
onLoaded: function(args){
console.log("onloaded");
getWorkItemFormService().then(function(service) {
service.getFieldValues(["System.Id","System.Title"]).then(function(value){
$(".events").append($("<div/>").text("onLoaded - " + JSON.stringify(value)));
console.log("WORK ITEM VALUES : " + JSON.stringify(value));
});
});
},
// Called when the active work item is being unloaded in the UI
onUnloaded: function(args) {
console.log("onunloaded.");
$(".events").empty();
$(".events").append($("<div/>").text("onUnloaded - " + JSON.stringify(args)));
},
// Called after the work item has been saved
onSaved: function (args) {
$(".events").append($("<div/>").text("onSaved - " + JSON.stringify(args)));
},
// Called when the work item is reset to its unmodified state (undo)
onReset: function (args) {
$(".events").append($("<div/>").text("onReset - " + JSON.stringify(args)));
},
// Called when the work item has been refreshed from the server
onRefreshed: function (args) {
$(".events").append($("<div/>").text("onRefreshed - " + JSON.stringify(args)));
}
}
});
});
});

vss-extension.json 文件:

{
"manifestVersion": 1,
"id": "sample-extension",
"version": "0.1.64",
"name": "sampleextension",
"displayName":"Sample Extension",
"description": "Sample Extension",
"publisher": "[RETRACTED]",
"contentType":"application/json",
"targets": [
{
"id": "Microsoft.VisualStudio.Services"
}
],
"icons": {
"default": "images/icon.png"
},
"contributions": [
{
"id": "sample-extension-page",
"type": "ms.vss-work-web.work-item-form-page",
"description": "Sample extenion page",
"targets": [
"ms.vss-work-web.work-item-form"
],
"properties": {
"name": "sample-extenion-page",
"uri": "hello-world.html"
}
}
],
"scopes": [
"vso.work"
],
"files": [
{
"path": "scripts", "addressable": true
},
{
"path": "sdk/scripts", "addressable": true
},
{
"path": "images/icon.png", "addressable": true
},
{
"path":"hello-world.html","addressable":true
}
]
}

我遇到了类似的问题...但这是用户错误。我在我的配置页面上注册了这个:

VSS.register("HelloWorldWidget.Configuration", function () {   

然后在我的清单中,我有:

{
"id": "TestWaffleWidget.Configuration",
"type": "ms.vss-dashboards-web.widget-configuration",
"targets": [ "ms.vss-dashboards-web.widget-configuration" ],
"properties": {
"name": "HelloWorldWidget Configuration",
"description": "Configures HelloWorldWidget",
"uri": "configuration.html"
}
}

这不会协调("HelloWorldWidget.Configuration"和"TestWaffleWidget.Configuration"不匹配(,然后引发"在任何消息通道上找不到处理程序"错误。

看起来您可能陷入了同样的问题。您正在注册:

VSS.register(VSS.getContribution().id, function(){

但是,除非VSS.getContribution().id与清单中的"示例扩展页面"匹配,否则它将引发无处理程序错误。

这个问题刚刚发生在我身上。

我发现原因是explicitNotifyLoaded没有设置。 以下内容对我有用:

  1. explicitNotifyLoaded设置为true
  2. 确保instanceIdcontribution id相匹配。
  3. 确保我在调用后VSS.notifyLoadSucceeded()VSS.registerVSS.require()回调

另一点,contributionIdVSS.getContribution().id,因为这会返回{provider}.{extensionid}.{contribution id}.您只需要contribution id.

注释状态小部件.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="../lib/VSS.SDK.min.js"></script>
</head>
<body>
<div class="widget">
<div id="root"></div>
</div>
<script type="text/javascript" src="AnnotationStatusWidget.js" charset="utf-8"></script>
</body>
</html>

AnnotationStatusWidget.tsx

import wh from "TFS/Dashboards/WidgetHelpers"
import {WidgetSettings} from "TFS/Dashboards/WidgetContracts"
import { showRootComponent } from "../../Common";
import * as React from "react";

const AnnotationStatusWidget : React.FunctionComponent<{}>  = ({}) => {

const [isValidationOpened, setIsValidationOpened] = React.useState<boolean>(false);
return <>Hello World</>
}
// Initialize the VSS sdk
VSS.init({
usePlatformScripts: true,
usePlatformStyles: true,
explicitNotifyLoaded: true
});
VSS.ready(() => {
VSS.require(["TFS/Dashboards/WidgetHelpers"], function (WidgetHelpers: typeof wh) { 
WidgetHelpers.IncludeWidgetStyles();
VSS.register("AnnotationStatusWidget", function () { 
var projectId = VSS.getWebContext().project.id;
return {
load: async (widgetSettings: WidgetSettings) => {
showRootComponent(<AnnotationStatusWidget/>);
return await WidgetHelpers.WidgetStatusHelper.Success();
}
}
});
VSS.notifyLoadSucceeded();
});

})

vss-extension.json


{
...
"contributions": [
{
"id": "AnnotationStatusWidget",
"type": "ms.vss-dashboards-web.widget",
"targets": [
"ms.vss-dashboards-web.widget-catalog"
],
"properties": {
"name": "Hello World Widget",
"description": "My first widget",
"catalogIconUrl": "pipeline-run-annotation-widgets/img/CatalogIcon.png",
"previewImageUrl": "pipeline-run-annotation-widgets/img/preview.png",                            
"uri": "pipeline-run-annotation-widgets/dist/AnnotationStatusWidget/AnnotationStatusWidget.html",
"supportedSizes": [
{
"rowSpan": 1,
"columnSpan": 2
}
],
"supportedScopes": ["project_team"]
}
}
],
"scopes": ["vso.work"]
}

您是否将 explicitNotifyLoaded 设置为 true? 通过此设置,我不会显示错误:

VSS.init({
explicitNotifyLoaded: true,
usePlatformScripts: true
});
VSS.ready(function () {
VSS.register(VSS.getContribution().id, function (context) {
return {
// ...
};
});
VSS.notifyLoadSucceeded();
});

你需要在函数之后调用VSS.notifyLoadSucceeded()函数VSS.register()函数(VSS.require()函数内部(。

我在这里也是一个大菜鸟,我也花了很多时间在这上面。我仔细遵循了 https://github.com/microsoft/vsts-extension-samples/tree/master/work-item-form 的例子,在我的情况下,问题是指完整的ID。

在示例工作项工具栏按钮中.html文件具有:

// Register a listener for the menu item contribution
VSS.register("Fabrikam.samples-work-item-form.sample-work-item-menu", function (context) {
return {
// Called when the menu item is clicked.
execute: function(actionContext) {
window.alert("Total fields changed: " + changedFieldCount[actionContext.workItemId]);
}
}
});

删除这部分后,它立即工作(我不知道为什么...

VSS.register(">Fabrikam.samples-work-item-form.示例工作项菜单",函数(上下文({

注意:在尝试这个之前,我彻底检查了 ID 拼写很多次,但仍然没有帮助。

最新更新