【Web API】AttributeRoutesのソリューションを追加できません

1798 ワード

1.マイクロソフトの公式文書によると、AttributeRoutesを使用するにはAPP_STARTのWebApiConfig.csのRegisterメソッドに行を追加:config.MapHttpAttributeRoutes();
public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable return type.
            // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
            // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
            //config.EnableQuerySupport();

            // To disable tracing in your application, please comment out or remove the following line of code
            // For more information, refer to: http://www.asp.net/web-api
            config.EnableSystemDiagnosticsTracing();
        }

しかし、私はそれを追加した後、命を誤って報告し、小さな赤い線を引いて、ピューピューピューピュー
後に解決策が判明したのは,属性ルーティングがWebAPI 2に加えられているため,VSをWebAPI 2にアップグレードする必要があるためである.メニューバーTools->NuGet package manager--->package manager consoleで、次のコマンドを入力します.
Install-Package Microsoft.AspNet.WebApi.WebHost
運行が終わって、VSを再起動して、赤い線は不思議に消えたのではありませんか、ララ
2.アップグレード後、コードを書いて実行するときにまた問題が発生したなど、いくつかの問題が発生します.エラーメッセージは以下の通りです.
'CommonServices.Areas.HelpPage.XmlDocumentationProvider' does not implement interface member 
解決策は、package manager consoleを呼び出し、次のコマンドを実行します.
install-package Microsoft.AspNet.WebApi.HelpPage
問題が解決した