VS 2017 WebAPI Help Page - No Document Provided

余生颓废 提交于 2019-12-01 04:31:34

问题


I have followed the steps at MSDN, and other SO questions, to setup documenting and to have the XML comments show in the descriptions section of the help page. However, I am receiving errors when I try to build or run the project. Visual Studio 2017 no longer has the "Build" selection in properties. It has been replaced by the "Compile" section. While this section does have the "Generate XML documentation file" option, it does not have a XML documentation file location option (as in the MSDN directions). That being said, we know that the XmlDocumentProvider is looking for "~/App_Data/XmlDocument.xml" in the HelpPageConfig.vb file.

First when I run the project it returns with a "No Document Provided" error, because, well, there is no document there. When I create an XML document "XMLDocument.xml" in the App_Data folder an error returns saying "No Root Element Found." After adding a root element no errors are returned; however, no descriptions show up in the help page either.

Setup:

  • Confirm AreaRegistration.RegisterAllAreas() is in Application_Start
  • Uncommented config.SetDocumentationProvider in HelpPageConfig.vb
  • Added comments to all controllers

I've tried:

  • Set Copy to Output Directory: Copy if newer
  • Variety of root element names (Description, Comments, Root, etc)

Does anyone know what the root element should be, or if there is a way to get VS 2017 to auto-generate the file if it does not exist?


回答1:


I know this answer comes very late, but I ran into the same problem. I could not get Visual Studio 2017 to output the XML Documentation file to the suggested ~/App_Data/XmlDocument.xml location.

However, I found that the correct file is generated under ~/bin/<project name>.xml. So if your project is "TestWebAPI2", then this file should be ~/bin/TestWebAPI2.xml.

(I couldn't see if there was a way to move/copy this file to ~/App_Data, but I didn't look for a very long time)

To get this working, go to ~/Areas/HelpPage/App_Start/HelpPageConfig.vb and change the following line to suit:

config.SetDocumentationProvider(New XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")))

becomes

config.SetDocumentationProvider(New XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/bin/<yourprojectname>.xml")))

(don't forget to replace <yourprojectname> with your WebAPI2 project name)




回答2:


You can do this properly by

1) If you don't have an App_Data folder, add it by right clicking on the project in Solution Explorer, then Add | Add Asp.Net Folder | App_Data

2) Go to the Build section of Project Properties. Under Output, check XML documentation file. In the edit box, type "App_Data/XmlDocument.xml"

Instructions can be found in this link

.




回答3:


API help not show Body Parameters descriptions. In class properties missing description info. Just add DescriptionAttribute to property:

    [Description("Simple description")]
    public string Text { get; set; }

This is my fix:

            public string GetDocumentation(MemberInfo member)
            {
                string memberName = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", GetTypeName(member.DeclaringType), member.Name);
                string expression = member.MemberType == MemberTypes.Field ? FieldExpression : PropertyExpression;
                string selectExpression = String.Format(CultureInfo.InvariantCulture, expression, memberName);
                XPathNavigator propertyNode = _documentNavigator.SelectSingleNode(selectExpression); 
                var result = GetTagValue(propertyNode, "summary") ?? GetDescription(member);
                return result; 
            }
            private static string GetDescription(MemberInfo memberInf)
            {
                var result = (memberInf.GetCustomAttribute(typeof(DescriptionAttribute)) as DescriptionAttribute)?.Description;
                return result;
            }

screenshot



来源:https://stackoverflow.com/questions/50844202/vs-2017-webapi-help-page-no-document-provided

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!