问题描述
我使用asp样板模板创建了一个Angular SPA项目,并根据this issue中的建议为示例功能的控制器实现添加了摘要。
/// <summary>
/// This is my sample function
/// </summary>
/// <returns></returns>
public Task SummaryTestMethod()
{
return Task.CompletedTask;
}
但是,昂首阔步的UI似乎没有记录我的言论。到目前为止,我还没有更改代码中的任何其他部分。默认配置是否不应包含这些备注?可能是什么问题?
解决方法
您可以按照以下步骤操作:
1。启用XML文档的创建。在 Solution Explorer 中,右键单击该项目,然后单击 Properties 。点击构建标签,然后导航至输出。确保已选中 XML文档文件选项。您可以保留默认文件路径:
2。您需要对我们的Startup.cs文件进行一些更改,以使您大摇大摆地使用这些注释:
services.AddSwaggerGen(c =>
{
//1.locate the xml file being generated
//if you choose the default file path in the first step,//the file name is SolutionName.xml
//the file path is the project path
var xmlFile = $"{Assembly.GetEntryAssembly().GetName().Name}.XML";
var xmlPath = Path.Combine(AppContext.BaseDirectory,xmlFile);
//2.tell swagger to use those xml comments
c.IncludeXmlComments(xmlPath);
//...
}
结果:
参考: