netcore 添加swagger

1.添加相应的nuget包

 2.配置服务和swaggerui

startup.cs 中

configureServices 中添加下面代码:

//swagger
            services.AddSwaggerGen();
            services.ConfigureSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new Info
                {
                    Version = "v1",
                    Title = "Ucent API"
                });

                options.IncludeXmlComments(Path.Combine("./Ucent.xml"));
                options.DescribeAllEnumsAsStrings();
   
            });

Configure 中添加:

            //swagger
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                string swaggerJsonBasePath = string.IsNullOrWhiteSpace(c.RoutePrefix) ? "." : "..";
                c.SwaggerEndpoint($"{swaggerJsonBasePath}/swagger/v1/swagger.json", "My API");
            });

3.修改输出目录

 注意:路径跟ConfigureServices中配置的路径对用

4.修改lanchSettings.json

 修改启动路径

原文地址:https://www.cnblogs.com/leolzi/p/11752052.html