dotnet core swagger with xml doc

You need to add following to csrpoj

<PropertyGroup>
	<DocumentationFile>EmployerApi.xml</DocumentationFile>
	<NoWarn>1701;1702;1591</NoWarn>
</PropertyGroup>

Notes:

  • do not forget to change xml file name to match csproj file name
  • NoWarn - 1701, 1702 - default ones, 1591 - to not warn about places without xml docs

Then in Startup.cs add

// ...
using System.IO;

namespace EmployerApi
{
	public class Startup
	{
		// ...
		public void ConfigureServices(IServiceCollection services)
		{
			// ...
			services.AddSwaggerGen(c =>
			{
				// ...
				c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "EmployerApi.xml"));
				c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "EmployerCode.xml"));
			});
		}

		// ...
	}
}

Notes:

  • you need to add XML for each class library
  • files by default are copied to resulting folder with all compiled dll

Links: