ASP.Net MVC - Swashbuckle 无法识别任何控制器

ASP.Net MVC - Swashbuckle Not Recognizing Any Controllers

我正在尝试使用 Swashbuckle 将 Swagger UI 集成到我的 ASP.Net MVC 项目中,但我遇到了 Swashbuckle 无法识别我的任何 controllers/endpoints.

的问题

为简单起见,我创建了一个带有单个控制器的全新项目,如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace TestAPI.Controllers
{
    public class HomeController : Controller
    {
        [Route("Home")]
        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }

        [Route("Home/About")]
        [HttpGet]
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        } 

        [Route("Home/Contact")]
        [HttpGet]
        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
   }
}

我使用 Nuget 使用以下命令添加 Swashbuckle:

Install-Package Swashbuckle

我保留了整个项目以及 Swashbuckle 本身的所有默认配置(使用生成的文件 SwaggerConfig.cs)

当我导航到 Swagger 端点时,我看到一个空的 Swagger 定义,我的 controllers/endpoints 的 none 正在显示。

Empty Swagger Definition

我不知道如何让我的 Controllers/Endpoints 出现。所有 Swashbuckle 演示都让这个基本配置看起来至少会显示端点。

谢谢!

编辑:以下是我的 SwaggerConfig.cs

using System.Web.Http;
using WebActivatorEx;
using TestAPI;
using Swashbuckle.Application;

[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]

namespace TestAPI
{
    public class SwaggerConfig
    {
        public static void Register()
        {
            var thisAssembly = typeof(SwaggerConfig).Assembly;

            GlobalConfiguration.Configuration
            .EnableSwagger(c =>
            {
                c.SingleApiVersion("v1", "TestAPI");
            })
            .EnableSwaggerUi();
        }
    }
}

这个问题的答案是 Swashbuckle 不适用于 ASP.Net MVC。不幸的是,Swashbuckle 不是解决此问题的合适解决方案。我最终使用反射和 XML 评论的组合创建了一个自定义解决方案。