8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ASP.NET MVC Web API のヘルプページへドキュメントを反映させる

Posted at

ASP.NET MVC プロジェクトをWebAPIで作成すると、ヘルプページが自動で作成されてとても便利です。

そんなの知らないぜ、欲しいぜって方はNuGetからインストールできます。(MVC 5 だと初めから入ってました)

Install-Package Microsoft.AspNet.WebApi.HelpPage

しかし、そのまま公開されたヘルプページを見てみると、関数のドキュメントはことごとく無視され、Descriptionなどは空のままです。
これではヘルプにならない!

sc0057.png


そこで、ソース内のドキュメントをxmlとして出力し、ヘルプページに読み込んでもらうように設定します。

ヘルプページ設定

  1. {Project}\Areas\HelpPage\App_Start\HelpPageConfig.cs を開く
  2. Register関数の始めにある↓を(言われるがまま)アンコメント
//// Uncomment the following to use the documentation from XML documentation file.
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));

xmlの保存

  1. webプロジェクトのプロパティを開く
  2. ビルド > 出力 にある XMLドキュメントファイルをチェック
  3. 先ほどHelpPageConfig.csで設定したパスを出力先として設定
    toritori.png

確認

ビルドしたら実行してみます。
sc0058.png

マーベラス!
あとは好みに合わせて外観をカスタマイズしていきましょう。

あと、この状態でビルドすると
ヘルプに関係ない関数でも「xmlコメントがないですよ!」と嬉々として警告をだしてくれますが、
それ、あなたたちが自動生成したソースでしょ...。

8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?