dotnet-cstomd 2.1.0

dotnet tool install --global dotnet-cstomd --version 2.1.0
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local dotnet-cstomd --version 2.1.0
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=dotnet-cstomd&version=2.1.0
                    
nuke :add-package dotnet-cstomd --version 2.1.0
                    

CsToMd

Idea and Overview

NuGet Badge

The dotnet CLI tool to convert C# file with Unit Tests into the Markdown documentation.

The idea is to have a normal C# .cs file with the special comments /*md, md*/, and //md which will be stripped when converting the file into the respective Markdown .md file. There are a couple of additional features but this is basically it.

Now you have the documentation always up-to-date with the runnable samples in the normal .NET Test library project with NUnit, XUnit, etc.

You may check the DryIoc documentation project for the real-world case example.

The additional features:

  • Directive to automatically wrap code in code fence with the optional language, e.g. add //md code:csharp, or just //md code: to add fences, and //md code:-- to stop adding fences. The directive may be used multiple times through the file.
  • Converting the section outlined with //md{ and //md} comments into the collapsed markdown details.
  • The optional cstomd.config file in the folder with the lines starters to be removed completely from the generated documentation file.

Dotnet CLI tool

The dotnet-cstomd is a dotnet CLI tool. It may be called from the command line and from the MSBuild scripts (enabling the document generation in the build pipeline).

I addition the dotnet tool enables the documentation development in the Visual Studio Code.

VSCode usage

Ad-hoc document generation

  • Install the dotnet-cstomd globally from the nuget, e.g. in the shell of your choice dotnet tool install --global dotnet-cstomd --version 1.2.1. Now you can invoke cstomd MyClass.cs directly and get the MyClass.md output.

Build integration

  • Switch to your project: cd path\to\MyProject

  • Add the tool manifest file: dotnet new tool-manifest

  • Install the tool: dotnet tool install dotnet-cstomd --version 1.2.1 --roll-forward (the manifest file will be updated and later used for restore)

  • Add the section to your project:

    <ItemGroup>
        <DocFile Include="**\*.cs" />
    </ItemGroup>
    
    <Target Name="MdGenerate" BeforeTargets="BeforeBuild">
        <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet cstomd %(DocFile.Identity)" />
    </Target>
    

    You may check the DryIoc documentation project file for the real-world case example.

  • You may run the document generation target without the rest of the build:

 dotnet msbuild -target:MdGenerate path\to\MyProject\MyProject.csproj

You may create a helper shell script with the command above.

Here is the MS tutorial for installing and using the local tools.

Visual Studio extension

This extension for Visual Studio 2019+ contains the CustomTool File Generator.

When applied to the C# source file it looks like this:

Screenshot

How to use

  • Install the extension directly from the marketplace in Visual Studio or download the extension vsix file from the release page.
  • In properties of your .cs file set the CustomTool property to CsToMd.
  • Save the .cs file
  • Check the generated .md file under the .cs file in Solution Explorer
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
2.1.0 203 4/13/2025
2.0.1 351 9/14/2024
1.2.1 1,731 8/31/2020
1.2.0 480 8/28/2020
1.0.0-preview-04 367 8/24/2020
1.0.0-preview-03 358 8/21/2020
1.0.0-preview-02 371 8/21/2020
1.0.0-preview-01 335 8/21/2020

## v2.1.0 Major release

- feature: #15 Directive to wrap code in Markdown code blocks
- feature: #16 Ignore leading whitespace before md comments
- feature: #17 Allow to close the md comment without md prefix
- feature: #20 Support collapsible section with multiline comments

- change: #18 Avoid removing md comments inside the normal comments
- change: #21 Avoid making collapsible section summary bold via strong tag - Users may do that themselves

**Full Changelog**: https://github.com/dadhi/CsToMd/compare/v2.0.1...v2.1.0