我编写了一个会产生错误的源生成器,我希望能够通过转到文档页面为用户提供有关他们所遇到的特定错误的更多信息。
幸运的是 DiagnosticDescriptor 有一个
helpLinkUri
字段,描述为:
可选超链接,提供有关诊断的更详细描述。
但是当我尝试通过将
helpLinkUri
设置为测试网站(如 google.com
、http://google.com
、https://google.com
或 www.google.com
)来使用此功能时,我会被发送到 https://learn.microsoft.com/en -us/visualstudio/ide/not-in-toc/default 这不是我设置的。这是使用 Visual Studio 并单击错误面板中的错误代码时的情况。
如何打开自定义网页进行源生成器诊断?是否存在文档未提及的限制?这是 Visual Studio 中存在的限制吗?
代码示例:
private static void ErrorMessage(SourceProductionContext _arg1, AttributeSourceWithContext _arg2)
{
DiagnosticDescriptor errorType = new DiagnosticDescriptor(
id: "Error1",
title: "Incorrect line",
messageFormat: "This is complex, open help link for good explanation",
helpLinkUri: "google.com", // <----- this is not opened when inspecting the error
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);
Diagnostic errorInstance = Diagnostic.Create(errorType, _arg2.GetLocation());
_arg1.ReportDiagnostic(errorInstance);
}
我有同样的问题。
还有一种链接会写在消息后面的“描述”栏中。如果您单击它,Visual Studio 就会崩溃。
正如您在 Visual Studio 中使用源生成器时所知,它们并不总是按编码运行。
不要害怕 -
尝试清理您的解决方案,构建,重新启动 Visual Studio,然后 重建您的解决方案。
这些是编码源生成器的四骑士。
第一次构建或重建时,会发生生成器的某种缓存。
您有时会注意到这一点,如果您开始编码并在生成器中编辑 LiteralString 值,最终文档中的更改并不总是立即发生。
但是,在生成器的目标文件中进行编辑,几乎会立即更改最终结果 - 当然,当生成器工作时。
最后我让它可以使用:
new DiagnosticDescriptor(
"ErrorCodeXXXX",
"Dumb code title",
"The code right here is dumb and dont always work as intended.",
"DumbFeatureError",
DiagnosticSeverity.Error,
true,
helpLinkUri: "https://DocLink.Domain/InternalDoc")
编辑: 现在我再次查看您的代码,也可能是因为您的网址中没有“https://”。