1.项目生成xml

.Net Core之Swagger

 

2.添加链接文件,并将属性设值为始终复制

.Net Core之Swagger

 

 

 

3.添加swagger引用:Swashbuckle.AspNetCore

 

 

4.startup.cs配置swargger的xml来源:

ConfigureServices方法添加:

            services.AddMvc();
            services.AddOptions();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info { Title = "DVM AdsPlatformProxy Service WebApi", Version = "v1.0.0.3" });
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                var docPath = Path.Combine(basePath, "Docs");
                var docs = XMLUtil.CreateXPathDocumentsFromDirectory(docPath);
                docs.ForEach(xp => c.IncludeXmlComments(() => { return xp; }));
            });//swagger文件路径配置
            services.RegisterServiceR<ILogBase, NLogger>(IocLifeStyle.Singleton);

  

 

Configure方法添加

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "DVM AdsPlatformProxy Service WebApi V1");
            });//swagger ui


            app.UseStaticFiles();

            app.UseMvc();

  

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2019-12-06
  • 2021-08-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案