Visual Studio C#源代码生成器诊断文档页面链接

jucafojl  于 2023-11-21  发布在  C#
关注(0)|答案(1)|浏览(177)

我写了一个源代码生成器,它会创建一个错误,我希望能够给予用户更多的信息,他们通过去一个文档页面的具体错误。
幸运的是,DiagnosticDescriptor有一个helpLinkUri字段,描述为:
一个可选的超链接,提供有关诊断的更详细的描述。
但是当我尝试通过将helpLinkUri设置为google.comhttp://google.comhttps://google.comwww.google.com等测试网站来使用此功能时,我会被发送到https://learn.microsoft.com/en-us/visualstudio/ide/not-in-toc/default,这不是我设置的。这是在使用Visual Studio并单击错误面板中的错误代码时发生的。
如何打开源代码生成器诊断的自定义网页?是否有文档中没有提到的限制?这是Visual Studio中存在的限制吗?
代码示例:

  1. private static void ErrorMessage(SourceProductionContext _arg1, AttributeSourceWithContext _arg2)
  2. {
  3. DiagnosticDescriptor errorType = new DiagnosticDescriptor(
  4. id: "Error1",
  5. title: "Incorrect line",
  6. messageFormat: "This is complex, open help link for good explanation",
  7. helpLinkUri: "google.com", // <----- this is not opened when inspecting the error
  8. defaultSeverity: DiagnosticSeverity.Warning,
  9. isEnabledByDefault: true);
  10. Diagnostic errorInstance = Diagnostic.Create(errorType, _arg2.GetLocation());
  11. _arg1.ReportDiagnostic(errorInstance);
  12. }

字符串

t3psigkw

t3psigkw1#

我也有同样的问题。
还有一个链接会写在消息后面的描述列中。如果你点击它,Visual Studio会崩溃。
正如您可能知道的那样,在Visual Studio中使用源代码生成器时,它们并不总是按照编码的方式工作。
别害怕-
尝试清理解决方案,生成,重新启动Visual Studio,然后重新生成解决方案。
这是编码源代码生成器的四个骑士。
第一次构建或重建时,会发生生成器的某种缓存。
你有时会注意到这一点,如果你开始编码并在生成器中编辑一个LiteralString值,最终文档中的更改并不总是立即发生。
然而,在生成器所针对的文件中进行编辑,几乎会立即更改最终结果-当然是在生成器工作时。
最后,我得到了它的工作:

  1. new DiagnosticDescriptor(
  2. "ErrorCodeXXXX",
  3. "Dumb code title",
  4. "The code right here is dumb and dont always work as intended.",
  5. "DumbFeatureError",
  6. DiagnosticSeverity.Error,
  7. true,
  8. helpLinkUri: "https://DocLink.Domain/InternalDoc")

字符串
编辑:现在我再次查看您的代码,这也可能是因为您的URL中没有“https://”。

展开查看全部

相关问题