我写了一个源代码生成器,它会创建一个错误,我希望能够给予用户更多的信息,他们通过去一个文档页面的具体错误。
幸运的是,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);
}
字符串
1条答案
按热度按时间t3psigkw1#
我也有同样的问题。
还有一个链接会写在消息后面的描述列中。如果你点击它,Visual Studio会崩溃。
正如您可能知道的那样,在Visual Studio中使用源代码生成器时,它们并不总是按照编码的方式工作。
别害怕-
尝试清理解决方案,生成,重新启动Visual Studio,然后重新生成解决方案。
这是编码源代码生成器的四个骑士。
第一次构建或重建时,会发生生成器的某种缓存。
你有时会注意到这一点,如果你开始编码并在生成器中编辑一个LiteralString值,最终文档中的更改并不总是立即发生。
然而,在生成器所针对的文件中进行编辑,几乎会立即更改最终结果-当然是在生成器工作时。
最后,我得到了它的工作:
字符串
编辑:现在我再次查看您的代码,这也可能是因为您的URL中没有“https://”。