280

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?

1

7 Answers 7

312
+350

Try:

///<Summary>
/// This is a math function I found <see href="http://stackoverflow.com">HERE</see>
///</Summary>
Sign up to request clarification or add additional context in comments.

14 Comments

No luck I'm afraid. It didn't even display "HERE".
Hmmm, my apologies. I did a little more research (see here and here) -- 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.
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&amp;test2=2 it worked.
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.
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..
|
117

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.

7 Comments

Actually, with ReSharper and CTRL+SHIFT+F1 an url is clickable and HTML link is compatible, so that's indeed the best option
Thanks Thomas Hagström, updated the anwer and screenshot.
+1 just confirmed that JetBrains Rider (the complete C# IDE from JetBrains with many of the Resharper features) only supports <a href="...">text</a> and will NOT display the link or text if you try <see href="...">text</see>
For me, I can use a, see, and seealso inside a summary /// <summary> /// Some Txt<br/> /// <a href="https://www.google.com/search?q=c%23+XML+comments&amp;sca_esv=5fddc3dd36c4976b">a with href</a><br/> /// <see href="https://www.google.com/search?q=c%23+XML+comments&amp;sca_esv=5fddc3dd36c4976b">see with href</see><br/> /// <seealso href="https://www.google.com/search?q=c%23+XML+comments&amp;sca_esv=5fddc3dd36c4976b">seealso with href</seealso><br/> /// </summary> Visual Studio Community 2022 Version 17.8.6 + JetBrains ReSharper 2023.2.2
Note that seealso is a bit odd, and probably should not be used generally. i.e. seems was intended to power a diff section, and supposedly should NOT be used in summary tags, but for intellisense it seems it is ignored when NOT in a summary tag. So... prob best to use <see href=""> or <a href="">
|
76

You can use the standard HTML syntax:

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

The text will be displayed in Visual Studio.

4 Comments

This is the best approach. As the output will still make sense in Visual Studio (it just shows the text) and the link will work in documentation tools like Sandcastle.
The link becomes clickable in VS 2022. This should be the accepted answer.
Only this way works for me in JetBrains Rider 2021.3
It is the only one that worked for me in Rider 2023.2.3
30

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>

Comments

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.

2 Comments

There’d be a point if Object Browser actually made <see/> clickable and recognized website URIs somehow (since Object Browser is not a tooltip). Just sayin’ ;-).
This approach is now outdated; it produces code analysis warning CA1200: Avoid using cref tags with a prefix. Prefer anchor tags (<a href="...">).
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.

Comments

0

Working solution:

/// <remarks>
/// <![CDATA[ Wireframe link: https://9ljx1q.axshare.com/#id=pinlb0&amp%3Bp=employee_complaint_form&amp%3Bg=1%3B2 ]]>
/// </remarks>

where, The <![CDATA[ and ]]> tags indicate character data that should not be parsed as XML, allowing you to include special characters without XML parsing issues.

if your Link( URL ) contains special characters like ',', '&', ';', then you have to replace it with HTML Character Entities Ex. & => &amp; , ;=> %3B

Otherwise, if your URL is simple, then <see href="http://stackoverflow.com">HERE</see> will work

Note: If you are planning to use a clickable URL, then remember that ASP.NET Core XML documentation doesn't support rendering hyperlinks.

And apart from that, it's better to display your link in a remark section because summary section text is not copyable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.