dotnet-markdown-sample-code
1.2.27
dotnet tool install --global dotnet-markdown-sample-code --version 1.2.27
dotnet new tool-manifest
dotnet tool install --local dotnet-markdown-sample-code --version 1.2.27
#tool dotnet:?package=dotnet-markdown-sample-code&version=1.2.27
nuke :add-package dotnet-markdown-sample-code --version 1.2.27
dotnet-markdown-sample-code
dotnet-markdown-sample-code allows users to copy sample code that is actually compiled and optionally also tested from a source code file into specially-marked sections in a markdown file, ensuring that sample code will not have syntax errors, and if called from tests, also ensures that the code works as intended.
Direct Usage
dotnet-markdown-sample-code [source [dest [language [timeout]]]]
sourceis the relative or full path to the source code from which samples should be extracted (default is Samples.cs)destis the relative or full path to the destination markdown file into which the sample code should be placed (default is README.md)languageis the markdown language specifier so that markdown can colorize the code sample properly (default is csharp)timeoutis the maximum number of seconds to keep trying to update the destination file (uses expontential backoff with random offset starting at 250ms, default is 30)
Sections in the Readme file where sample code is to be places are marked as follows:
[//]: # (MySampleSectionName)
```language
void MyFunction()
{
// my code here
}
```
Code to place into the Readme file is identified by #region/#endregion markers like this:
#region MySampleSectionName
void MyFunction()
{
// my code here
}
#endregion
For each region in the sample file, the corresponding Readme section is searched for, the current contents are removed (everything between and including the first two lines starting with triple-backtick), and everything between the #region and #endregion markers is put into that position in the Readme.
Samples Projects
If you have a sibling project containing sample code that may be compiled and/or tested, with the applicable sample code in Samples.cs at the tope level of the project and README.md one folder up (in the solution folder), add the following code to that project's project file:
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="dotnet-markdown-sample-code -- Samples.cs ../README.md" />
</Target>
Global Installation
dotnet tool install --global dotnet-markdown-sample-code --version <tool_version>
Local Installation
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local dotnet-markdown-sample-code --version <tool_version>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. 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 is compatible. 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 is compatible. 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 is compatible. 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 is compatible. 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. |
| .NET Core | netcoreapp3.1 is compatible. |
This package has no dependencies.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.27 | 150 | 7/29/2026 |
| 1.2.25 | 155 | 6/22/2026 |
| 1.2.23 | 136 | 5/5/2026 |
| 1.2.22 | 196 | 3/17/2026 |
| 1.2.21 | 123 | 3/17/2026 |
| 1.2.20 | 133 | 3/17/2026 |
| 1.2.19 | 172 | 1/22/2026 |
| 1.2.17 | 456 | 10/13/2024 |
| 1.2.16 | 490 | 7/28/2023 |
| 1.2.15 | 296 | 7/28/2023 |
| 1.2.14 | 359 | 7/28/2023 |
| 1.2.13 | 380 | 7/28/2023 |
| 1.2.12 | 371 | 4/1/2023 |
| 1.2.11 | 328 | 4/1/2023 |
| 1.2.10 | 377 | 4/1/2023 |
| 1.2.9 | 374 | 4/1/2023 |
| 1.2.8 | 427 | 3/19/2023 |
| 1.2.7 | 331 | 3/19/2023 |
| 1.2.6 | 337 | 3/19/2023 |
| 1.2.5 | 380 | 3/19/2023 |