1

For many years, one could use the <code/> element for all kinds of fixed format text as documented here. The documentation specifically mentions "multiple lines of code" and examples (like this one) are showing how this used to work for multi-line code examples.

However, recent versions of Visual Studio (2017, 2019) started to format the content of <code/> as freely flowing text, ignoring any line breaks. (If the element is in a class summary, the effect can be seen when hovering over the class name.)

So, suppose I have to put an XML snippet into the codedoc. I need newlines to be preserved, ideally without having to mark them with <br/>, so that they can be easily copy and pasted in and out.

How can I do that?

Jirka Hanika
  • 13,301
  • 3
  • 46
  • 75

2 Answers2

0

Try wrapping it in <example> tag:

The example tag lets you specify an example of how to use a method or other library member. This commonly involves using the code tag.

And example from docs:

    /// <summary>
    /// The GetZero method.
    /// </summary>
    /// <example>
    /// This sample shows how to call the <see cref="GetZero"/> method.
    /// <code>
    /// class TestClass
    /// {
    ///     static int Main()
    ///     {
    ///         return GetZero();
    ///     }
    /// }
    /// </code>
    /// </example>
    public static int GetZero()
    {
        return 0;
    }
Guru Stron
  • 102,774
  • 10
  • 95
  • 132
  • Same behavior. I tested using `code` inside an `example` inside a `summary` and it ended up as if the `example` just wasn't there. Of course, if I instead hid the example so well that VS would never find it and try to format it inside the IDE, then I would not be bothered by how it gets formatted. But that's not my goal. – Jirka Hanika Jun 03 '20 at 12:04
0

I always use \n to create a new line.