dotnet example
A dotnet tool to list and run examples similar to Rust's cargo run --example
.
Installing
> dotnet tool install -g dotnet-example
Listing examples
> dotnet example
โญโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Example โ Description โ
โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ CSharp โ Writes 'Hello from C#' to the console โ
โ FSharp โ Writes 'Hello from F#' to the console โ
โฐโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Type dotnet example --help for help
Running individual examples
> dotnet example csharp
Hello from C#
> dotnet example fsharp
Hello from F#
Running all examples
> dotnet example --all
โโ Example: CSharp โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Hello from C#
โโ Example: FSharp โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Hello from F#
Showing example source code
> dotnet example fsharp --source
โญโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ 1 โ // Learn more about F# at http://docs.microsoft.com/dotnet/fsharp โ
โ 2 โ โ
โ 3 โ open System โ
โ 4 โ โ
โ 5 โ // Define a function to construct a message to print โ
โ 6 โ let from whom = โ
โ 7 โ sprintf "from %s" whom โ
โ 8 โ โ
โ 9 โ [<EntryPoint>] โ
โ 10 โ let main argv = โ
โ 11 โ let message = from "F#" // Call the function โ
โ 12 โ printfn "Hello %s" message โ
โ 13 โ 0 // return an integer exit code โ
โฐโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Conventions
The convention is simple, if there is an examples
or samples
folder
in the directory the tool is executed in, it will fetch all csproj
/fsproj
files
and find the best match to the query.
If examples are located in unconventional folders, add a .examples
file
with the (relative) paths of the examples folders, one per line. Blank lines
or lines starting with #
in the .examples
file are ignored.
Example settings
To change the name, description, and the order of an example, edit its csproj
/fsproj
file, and add the following section:
<PropertyGroup>
<ExampleTitle>Foo</ExampleTitle>
<ExampleDescription>This is the description of the example.</ExampleDescription>
<ExampleOrder>5</ExampleOrder>
</PropertyGroup>
If no name is set in the csproj
file, the project name will be used.
To ignore an example, add the ExampleVisible
property in the example's csproj
/fsproj
file.
<PropertyGroup>
<ExampleVisible>false</ExampleTitle>
</PropertyGroup>