这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task When_the_template_is_installed_verify_works()
.Trim()
.Should()
.Match(
$"{outputDirectory}{Path.DirectorySeparatorChar}Readme.md*Line 24:*{outputDirectory}{Path.DirectorySeparatorChar}Program.cs (in project {outputDirectory}{Path.DirectorySeparatorChar}{outputDirectory.Name}.csproj)*".EnforceLF());
$"{outputDirectory}{Path.DirectorySeparatorChar}Readme.md*Line *:*{outputDirectory}{Path.DirectorySeparatorChar}Program.cs (in project {outputDirectory}{Path.DirectorySeparatorChar}{outputDirectory.Name}.csproj)*".EnforceLF());

resultCode.Should().Be(0);

Expand Down
27 changes: 12 additions & 15 deletions Microsoft.DotNet.Try.ProjectTemplate/Tutorial/content/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@

namespace Microsoft.DotNet.Try.ProjectTemplate.Tutorial
{
///<param name="region">Takes in the --region option from the code fence options in markdown</param>
///<param name="session">Takes in the --session option from the code fence options in markdown</param>
///<param name="package">Takes in the --package option from the code fence options in markdown</param>
///<param name="project">Takes in the --project option from the code fence options in markdown</param>
///<param name="args">Takes in any additional arguments passed in the code fence options in markdown</param>
///<summary>This program uses <a href="https://github.com/dotnet/command-line-api/wiki/DragonFruit-overview">System.CommandLine.DragonFruit</a> to accept command line arguments from command line.
///<example>Execute: dotnet run --region "HelloWorld" to see the output</example>
///</summary>
public class Program
{
///<param name="region">Takes in the --region option from the code fence options in markdown</param>
///<param name="session">Takes in the --session option from the code fence options in markdown</param>
///<param name="package">Takes in the --package option from the code fence options in markdown</param>
///<param name="project">Takes in the --project option from the code fence options in markdown</param>
///<param name="args">Takes in any additional arguments passed in the code fence options in markdown</param>
///<see>To learn more see <a href="https://aka.ms/learntdn">our documentation</a></see>
static int Main(
string region = null,
string session = null,
Expand All @@ -21,31 +25,24 @@ static int Main(
{
"HelloWorld" => HelloWorld(),
"DateTime" => DateTime(),
_ => EmptyRegion()
_ => throw new ArgumentException("A --region argument must be passed", nameof(region))
};
}

public static int HelloWorld()
internal static int HelloWorld()
{
#region HelloWorld
Console.WriteLine("Hello World!");
#endregion
return 0;
}

public static int DateTime()
internal static int DateTime()
{
#region DateTime
Console.WriteLine(System.DateTime.Now);
#endregion
return 0;
}

public static int EmptyRegion()
{
#region EmptyRegion
#endregion
return 0;
}
}
}
37 changes: 3 additions & 34 deletions Microsoft.DotNet.Try.ProjectTemplate/Tutorial/content/Readme.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,20 @@
# Creating interactive documentation with Try .NET

## Setup
Before getting started with the sample above, you need to install the `dotnet try` global tool. In a terminal execute
If you haven't installed the `dotnet try` global tool, you can install it by following the instructions [here](https://github.com/dotnet/try#setup).

```console
dotnet tool install --global dotnet-try
```

Once installed you can execute
```console
dotnet try -h
```
and see the list of available commands.

## Executing your first sample

In the directory of the project execute
```console
dotnet try
```
This should launch a browser window. The following code fence will be replaced by the editor and you can execute the code by hitting the run button.
## This code fence will run the HelloWorld method from Program.cs

```cs --source-file ./Program.cs --project ./Microsoft.DotNet.Try.ProjectTemplate.Tutorial.csproj --region HelloWorld
```

## What's happening behind the scenes

Code fences are a standard way to include code in your markdown files. The only change you need to do is to add few options in the first line of your code snippet. If you notice the above code snippet, there are three options in action.

| Option | What it does |
|----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
| `--project ./Microsoft.DotNet.Try.ProjectTemplate.Tutorial.csproj` | Points to the project that the sample is part of. (Optional. Defaults to any .csproj in the same folder as the `.md` file.) |
| `--region HelloWorld` | Identifes a C# code `#region` to focus on. (Optional. If not specified, the whole file is displayed in the editor.) |
| `--source-file ./Program.cs` | Points to the file where the sample code is pulled from.

If you navigate back to Program.cs you will be able to see the various regions and the context in which your code is being execute. As an exercise, try to change the region in the previous code snippet to `DateTime` and then refresh the browser. You should be able to see the text that is a part of the `DateTime` region now.

## Learn More

The above are the basic to get you started with creating your own interactive documentation. To learn more about the `dotnet try` features, at the command line execute
To learn more about the `dotnet try` features, at the command line execute

```console
dotnet try demo
```

This interactive demo will walk you through the various features in `dotnet try`.

## Feedback

We love to hear from you. If you have any suggestions or feedback please reach out to us on [GitHub](https://github.com/dotnet/try)