Examples
To call DocFx from a Cake script the Cake.DocFx addin can be used. To read issues from DocFx log files the DocFx issue provider needs to be imported:
build.cake
#addin nuget:?package=Cake.DocFx&version=1.0.0
#addin nuget:?package=Cake.Issues&version=5.2.0
#addin nuget:?package=Cake.Issues.DocFx&version=5.2.0
Note
In addition to the DocFx issue provider the Cake.Issues
core addin needs to be added.
Build.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Cake.DocFx" Version="1.0.0" />
<PackageReference Include="Cake.Frosting" Version="5.0.0" />
<PackageReference Include="Cake.Frosting.Issues.DocFx" Version="5.2.0" />
</ItemGroup>
</Project>
The following example contains a task which will build the DocFx project and write a log file and a task to read issues from the log file and write the number of warnings to the console:
build.cake
var logPath = @"c:\build\docfx.log";
var repoRootFolder = MakeAbsolute(Directory("./"));
var docRootPath = @"docs";
Task("Build-Documentation").Does(() =>
{
// Run DocFx.
DocFxBuild(new DocFxBuildSettings()
{
LogPath = logPath
});
});
Task("Read-Issues")
.IsDependentOn("Build-Documentation")
.Does(() =>
{
// Read issues.
var issues =
ReadIssues(
DocFxIssuesFromFilePath(logPath, docRootPath),
repoRootPath);
Information("{0} issues are found.", issues.Count());
});
Program.cs
using Cake.Common.Diagnostics;
using Cake.Core.IO;
using Cake.Core;
using Cake.DocFx;
using Cake.DocFx.Build;
using Cake.Frosting;
public static class Program
{
public static int Main(string[] args)
{
return new CakeHost()
.UseContext<BuildContext>()
.Run(args);
}
}
public class BuildContext(ICakeContext context) : FrostingContext(context)
{
public FilePath LogPath { get; } = @"c:\build\docfx.log";
public DirectoryPath RepoRootPath { get; } =
context.MakeAbsolute(context.Directory("./"));
public string DocRootPath { get; } = "docs";
}
[TaskName("Build-Documentation")]
public sealed class BuildDocumentationTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
// Run DocFx.
context.DocFxBuild(new DocFxBuildSettings()
{
LogPath = context.LogPath
});
}
}
[TaskName("Read-Issues")]
[IsDependentOn(typeof(BuildDocumentationTask))]
public sealed class ReadIssuesTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
// Read issues.
var issues =
context.ReadIssues(
context.DocFxIssuesFromFilePath(
context.LogPath,
context.DocRootPath),
context.RepoRootPath);
context.Information("{0} issues are found.", issues.Count());
}
}