239

Is it possible to include a link to a website in the XML documentation? For example, my method's summarized as

///<Summary>
/// This is a math function I found HERE.
///</Summary>
public void SomeMathThing(Double[] doubleArray)
{
   ...
}

and when I type

SomeMathThing(

I want IntelliSense to show the summary with the option to click on "HERE" to link to an outside website. Is this possible? How would it be done?

TylerH
  • 20,799
  • 66
  • 75
  • 101
john
  • 4,043
  • 7
  • 27
  • 39
  • This was implemented by this Roslyn issue on GitHub: [ tags in XML docs should be clickable links in the IntelliSense popups.](https://github.com/dotnet/roslyn/issues/39139) – Chiramisu Aug 05 '20 at 00:12

6 Answers6

259

Try:

///<Summary>
/// This is a math function I found <see href="http://stackoverflow.com">HERE</see>
///</Summary>
dizzwave
  • 4,013
  • 1
  • 19
  • 16
  • 17
    No luck I'm afraid. It didn't even display "HERE". – john Aug 05 '11 at 19:23
  • 9
    Hmmm, my apologies. I did a little more research (see [here](http://social.msdn.microsoft.com/Forums/en-US/devdocs/thread/8af32a12-bebe-447b-9111-dbe5d970810d) and [here](http://social.msdn.microsoft.com/Forums/en/csharpide/thread/82d85250-e5ac-48f2-a787-2ca441904c2c)) -- and it looks like the VS IDE won't display those hyperlinks, but a documentation tool such as SandCastle would be able to display them. – dizzwave Aug 05 '11 at 19:56
  • 2
    You can read about Sandcastle [here](http://elegantcode.com/2008/04/01/inline-xml-code-documentation-using-sandcastle/) btw. "Sandcastle, created by Microsoft, is a free tool used for creating MSDN-style documentation from .NET assemblies and their associated XML comment files. It is command-line based and has no GUI front-end, project management features, or an automated build process." HTH! – dizzwave Aug 05 '11 at 20:04
  • Anyone else having trouble getting this trick to work in CR_Documentor? It shows up if I use NDoc 1.3 preview style, but not if I use the Sandcastle option. – rkagerer Jan 17 '13 at 08:43
  • 1
    Note, there is some variability in support for as a content tag. I've found it a bit more consistent when used as a self closed tag just displaying the raw URL. (Which is better documentation anyway: as "HERE" is not providing much in the way of explanation.) – gremlin Mar 28 '19 at 20:16
  • 1
    This is not supported by Visual Studio, no Intellisense for `href` attribute. – Konard Aug 14 '19 at 11:27
  • 2
    For me it wasn't working because my link had an ampersand in the url. Once I changed that to `https://somewhere.com?test1=1&test2=2` it worked. – paulguy Oct 25 '19 at 18:14
  • 10
    This works in VS 16.4.2. Not sure what version it was added, only that you can now click links in the method info window. – JB06 Jan 09 '20 at 17:35
  • 4
    Works in VS 2019, the exact version number is VS 16.6.4. First I tried with "cref", but "href" renders nice. One trick is that when the tooltip hovers, move your mouse pointer not outside the tooltip and you can click on the link to navigate to the url too. Great stuff VS! Does it work in Vs Code too ? Hmmmm.. – Tore Aurstad Oct 24 '20 at 18:35
  • Also note it only works in the tag. It doesn't work in tags (VS 2019 v16.7.6). – Zodman Nov 10 '20 at 08:50
  • While VS (2019 v16.8) offers no intellisense for the `href` attribute, it does work great in both `summary` and `remarks`, both in `see` and `seealso` tags. – kzu Jan 28 '21 at 20:21
  • No anchor tag is created unfortunately – jjxtra Sep 02 '22 at 16:52
103

A bit late on the hype-train, but here is what I found out for Visual Studio 2015.

My sample looks like this:

    /// <summary>
    ///     Retrieves information about the specified window. 
    ///     The function also retrieves the value at a specified offset into the extra window memory.
    ///     From <see cref="!:https://msdn.microsoft.com/en-us/library/windows/desktop/ms633585(v=vs.85).aspx">this</see> MSDN-Link.
    ///     AHref <a href="http://stackoverflow.com">here</a>.
    ///     see-href <see href="http://stackoverflow.com">here</see>.
    /// </summary>
    /// <param name="hwnd"></param>
    /// <param name="index"></param>
    /// <returns>
    ///     Testlink in return: <a href="http://stackoverflow.com">here</a>
    /// </returns>
    public static IntPtr GetWindowLongPtr(IntPtr hwnd, int index)
    {
        return IntPtr.Size == 4 ? GetWindowLongPtr32(hwnd, index) : GetWindowLongPtr64(hwnd, index);
    }

The results are:

  1. Tooltip:
    • Shows cref-url with !:, but hides "this"
    • Hides ahref-url but shows text
    • Hides seehref url and text Screenshot of intellisense tooltip

  1. Object Browser:
    • Shows cref-url with !:, but hides "this" (not clickable)
    • Hides ahref-url but shows text (not clickable)
    • Hides seehref url and text (not clickable) Screenshot of ObjectBrowser

  1. ReSharper (CTRL+SHIFT+F1, Command ReSharper.ReSharper_QuickDoc)
    • Hides cref-url with !:, but shows "this" (not clickable)
    • Does now interpret ahref-url (Version from 2016 and newer)
    • Hides seehref url and text (not clickable) Screenshot of Resharper QuickHelp

Conclusion: Best one, as Heiner pointed out, would be

See <a href="link">this link</a> for more information.

Update As Thomas Hagström pointed out, Resharper now Supports clickable a-href URLs. Updated screenshot accordingly.

MHolzmayr
  • 1,541
  • 1
  • 12
  • 22
  • 2
    Actually, with ReSharper and CTRL+SHIFT+F1 an url is clickable and HTML link is compatible, so that's indeed the best option – Thomas Hagström May 31 '16 at 11:23
  • 1
    Thanks Thomas Hagström, updated the anwer and screenshot. – MHolzmayr Jun 01 '16 at 12:59
  • 2
    +1 just confirmed that JetBrains Rider (the complete C# IDE from JetBrains with many of the Resharper features) only supports `text` and will NOT display the link or text if you try `text` – Eric Mutta Apr 30 '23 at 19:54
67

You can use the standard HTML syntax:

<a href="http://stackoverflow.com">here</a>

The text will be displayed in Visual Studio.

Heiner
  • 1,869
  • 1
  • 19
  • 33
24

You can include a !: prefix in a cref to have it passed through untouched in the generated Xml documentation so that tools such as Innovasys Document! X and Sandcastle will use it. e.g.

/// <summary>
/// This is a math function I found <see cref="!:http://stackoverflow.com">HERE</see>
/// </summary>

Visual Studio intellisense won't display that as a link for intellisense though - wouldn't be much point as it's a tooltip so you can't click it anyway.

fubaar
  • 2,489
  • 1
  • 21
  • 21
  • 2
    There’d be a point if [Object Browser actually made `` clickable](http://stackoverflow.com/q/20517119/429091) *and* recognized website URIs somehow (since Object Browser is not a tooltip). Just sayin’ ;-). – binki Oct 17 '14 at 14:41
  • 1
    This approach is now outdated; it produces code analysis warning [CA1200: Avoid using cref tags with a prefix](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1200). Prefer anchor tags (). – Rab May 27 '21 at 12:50
21

Use the <a> tag. For example, I used this solution in my project:

Result:

My XML code:

/// <summary>
/// This is C# XML Documentation Website Link
/// <a href="https://stackoverflow.com/questions/6960426/c-sharp-xml-documentation-website-link">See more</a>
/// </summary>

Or use the <see> tag. Result is the same to the <a> tag.

/// <summary>
/// This is C# XML Documentation Website Link
/// <see href="https://stackoverflow.com/questions/6960426/c-sharp-xml-documentation-website-link">See more</see>
/// </summary>
Pang
  • 9,564
  • 146
  • 81
  • 122
Ramil Aliyev 007
  • 4,437
  • 2
  • 31
  • 47
3

I also tried <see href="https://some.com/> first and it did not work; however, I then tried <seealso href="https://some.url/"> and it did work.

gregsonian
  • 1,126
  • 13
  • 15