You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Visual Studio 2017的XML文档注释中实现换行?

在Visual Studio 2017的XML文档注释中添加换行的解决方案

在VS的XML文档注释里,纯文本的\n不会被解析为换行,要实现排版换行,需使用XML原生标签控制:

方法1:用<br/>标签强制换行

在需要拆分内容的位置直接插入<br/>,适合同一段内的换行需求:

public interface IPersonService : IDisposable
{
    /// <summary>
    /// Procedure that returns a list of people with the given first and last name.
    /// 
    /// <para>
    /// First and last names are not case sensitive. (&apos;friedrich schiller&apos; == &apos;fRieDrich scHIller&apos;)     
    /// </para>
    /// <example>
    /// The following example returns a list of people with the first name 'friedrich' and the last name 'schiller':<br/>
    /// <code>
    /// IList &lt;Person&gt; personList = _personService.GetList(&quot;friedrich&quot;,&quot;schiller&quot;);
    /// </code>
    /// </example>  
    /// </summary>
    /// <param name="name">Name of the person being called. It cannot be null. It is not case sensitive.</param>
    /// <param name="surname">Surname of the person being called. It cannot be null. It is not case sensitive.</param>
    /// <returns>
    /// IList&lt;Person&gt;: List of people with name and surname,<br/>
    /// Empty list: If there is no person matching the given name and surname.
    /// </returns>        
    IList<Person> GetList(string name, string surname);
}

方法2:用<para>标签创建段落换行

如果需要将内容拆分为独立段落,用<para>包裹对应内容,VS会自动在段落间添加合理的换行和间距,排版更规整:

public interface IPersonService : IDisposable
{
    /// <summary>
    /// Procedure that returns a list of people with the given first and last name.
    /// 
    /// <para>
    /// First and last names are not case sensitive. (&apos;friedrich schiller&apos; == &apos;fRieDrich scHIller&apos;)     
    /// </para>
    /// <example>
    /// <para>The following example returns a list of people with the first name 'friedrich' and the last name 'schiller':</para>
    /// <code>
    /// IList &lt;Person&gt; personList = _personService.GetList(&quot;friedrich&quot;,&quot;schiller&quot;);
    /// </code>
    /// </example>  
    /// </summary>
    /// <param name="name">Name of the person being called. It cannot be null. It is not case sensitive.</param>
    /// <param name="surname">Surname of the person being called. It cannot be null. It is not case sensitive.</param>
    /// <returns>
    /// <para>IList&lt;Person&gt;: List of people matching the given name and surname.</para>
    /// <para>Empty list: Returned when no matching people are found.</para>
    /// </returns>        
    IList<Person> GetList(string name, string surname);
}

原理说明

XML文档注释遵循XML语法规则,VS的注释解析器只会识别XML标签处理排版,普通文本中的换行符(\n)会被忽略。<br/>用于强制换行,<para>用于创建独立段落,两种方式都能在VS智能提示、生成的文档中正确渲染出换行效果。

内容的提问来源于stack exchange,提问作者tahasozgen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 13:47:35