找不到 XML 注释文件 - Swagger找不到、注释、文件、Swagger

2023-09-07 14:00:53 作者:你是我的心脏

这肯定是让你发疯的原因之一.正如标题所示,我只是想做的就是使用 swagger 显示从 xml 文件中提取的注释.

This is certainly one of those that drives you nuts. As the title indicates all I'm simply trying to do is display comments pulled from an xml file using swagger.

我似乎已根据 swagger 文档采取了所有步骤,但无济于事.希望各位好心人能给我指出正确的方向.

I appear to have taken all steps according to the swagger documentation but to no avail. Hopefully you kind folk can point me in the right direction.

采取的步骤:

确保文件存在:

配置的SwaggerConfig.cs

我也尝试过更改路径:@"bin/..xml"

I've tried changing the path too: @"bin/....xml"

似乎没有任何效果.

**错误找不到文件":**

**The Error "Could not find file": **

谁能指出我正确的方向?

Can anyone point me in the right direction please?

问候,

推荐答案

好的,所以我设法通过指向根目录来让它工作.

Ok, So I managed to get it to work by pointing to the root directory.

我仍然不知道为什么它无法检测到 bin 目录中的 xml 文件.这再次通过在根目录中添加一个 xml 文件来实现.

I still have no idea why it cannot detect the xml file in the bin directory. Again this worked by adding an xml file within the root.

代码更改:

var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
                        //var commentsFileName = Assembly.GetExecutingAssembly().GetName().Name + ".XML";
                        var commentsFileName = "Comments" + ".XML";
                        var commentsFile = Path.Combine(baseDirectory, commentsFileName);

                        c.IncludeXmlComments(commentsFile);