Serve Command

MkDocs serve command

This method swill block build process. Use Ctrl+C in console to quit.

MkDocs project in working directory

Serve MkDocs project:

MkDocsServe();

With settings:

MkDocsServe(new MkDocsServeSettings()
{
    DevAddr = new MkDocsAddress("localhost", 8090),
    Theme = MkDocsTheme.ReadTheDocs
});

Configuring timeout:

try
{
    MkDocsServe(new MkDocsServeSettings()
    {
        ToolTimeout = new TimeSpan(0, 0, 1, 0)
    });
}
catch (TimeoutException)
{
    // Kill tool process after 1 minute
}

MkDocs project in different directory

Serve MkDocs in provided directory:

MkDocsServe("./docs-project");
MkDocsServe(new DirectoryPath("./docs-project"));

With settings:

MkDocsServe"./docs-project", new MkDocsServeSettings()
{
    Dirty = true,
    Theme = MkDocsTheme.ReadTheDocs
});
MkDocsServe(new DirectoryPath("./docs-project") ,new MkDocsServeSettings()
{
    Dirty = true,
    Theme = MkDocsTheme.ReadTheDocs
});

Configuring timeout:

try
{
    MkDocsServe(new DirectoryPath("./docs-project"), new MkDocsServeSettings()
    {
        ToolTimeout = new TimeSpan(0, 0, 1, 0)
    });
}
catch (TimeoutException)
{
    // Kill tool process after 1 minute
}

MkDocs serve async command

This method will block build process. Use Ctrl+C in console to quit or use CancellationToken to cancel task programmatically.

MkDocs project in working directory

Serve MkDocs project:

var task = MkDocsServeAsync();
// Do work...
task.Wait();

With settings:

using (var tokenSource = new CancellationTokenSource())
{
    var task = MkDocsServeAsync(new MkDocsServeAsyncSettings()
    {
        Token = tokenSource.Token
    });

    // Do work...
    tokenSource.Cancel();

    try
    {
        task.Wait();
    }
    catch (OperationCanceledException)
    {
    }
}

Configuring timeout:

using (var tokenSource = new CancellationTokenSource())
{
    var task = MkDocsServeAsync(new MkDocsServeAsyncSettings()
    {
        ToolTimeout = new TimeSpan(0, 0, 1, 0)
    });

    // Do work...

    try
    {
        task.Wait();
    }
    catch (TimeoutException)
    {
        // Kill tool process after 1 minute
    }
}

MkDocs project in different directory

Serve MkDocs in provided directory:

var task = MkDocsServeAsync("./docs-project");
// Do work...
task.Wait();
var task = MkDocsServeAsync(new DirectoryPath("./docs-project"));
// Do work...
task.Wait();

With settings:

using (var tokenSource = new CancellationTokenSource())
{
    var task = MkDocsServeAsync("./docs-project", new MkDocsServeAsyncSettings()
    {
        Token = tokenSource.Token
    });

    // Do work...
    tokenSource.Cancel();

    try
    {
        task.Wait();
    }
    catch (OperationCanceledException)
    {
    }
}
using (var tokenSource = new CancellationTokenSource())
{
    var task = MkDocsServeAsync(new DirectoryPath("./docs-project"), new MkDocsServeAsyncSettings()
    {
        Token = tokenSource.Token
    });

    // Do work...
    tokenSource.Cancel();

    try
    {
        task.Wait();
    }
    catch (OperationCanceledException)
    {
    }
}

Configuring timeout:

using (var tokenSource = new CancellationTokenSource())
{
    var task = MkDocsServeAsync(new DirectoryPath("./docs-project"), new MkDocsServeAsyncSettings()
    {
        ToolTimeout = new TimeSpan(0, 0, 1, 0)
    });

    // Do work...

    try
    {
        task.Wait();
    }
    catch (TimeoutException)
    {
        // Kill tool process after 1 minute
    }
}
GitHub