{"id":23532,"date":"2019-06-20T09:05:37","date_gmt":"2019-06-20T16:05:37","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet\/?p=23532"},"modified":"2019-06-20T11:53:18","modified_gmt":"2019-06-20T18:53:18","slug":"create-interactive-documentation-with-the-new-try-net-template","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/create-interactive-documentation-with-the-new-try-net-template\/","title":{"rendered":"Create interactive documentation with the new Try .NET template"},"content":{"rendered":"<div class=\"Box-body\">\n<article class=\"markdown-body entry-content p-5\">In our <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/creating-interactive-net-documentation\/\" rel=\"nofollow\">previous post<\/a>, we announced <code>dotnet try<\/code>\u00a0a global tool which allows developers to create interactive workshops and documentation. Tutorials created with <code>dotnet try <\/code>let users start learning without having to install an editor. Features like IntelliSense and live diagnostics give users a sophisticated learning and editing experience. Today, we are releasing a new <code>dotnet new<\/code> template called <code>trydotnet-tutorial<\/code>. This template can be installed next to existing <code>dotnet new<\/code> templates. It creates a project and associated files to help content authors understand the basics of <code>dotnet try<\/code>. This can serve as the foundation of your own awesome documentation!<\/p>\n<h2>Setup<\/h2>\n<p>Before you get started with our new template please make sure that you have .NET Core SDK <a href=\"https:\/\/dotnet.microsoft.com\/download\/dotnet-core\/3.0\">3.0<\/a> and <a href=\"https:\/\/dotnet.microsoft.com\/download\/dotnet-core\/2.1\">2.1<\/a> installed.<\/p>\n<p>Now, let&#8217;s begin by installing the template. In a command prompt execute,<\/p>\n<p style=\"text-align: center;\"><code>dotnet new -i Microsoft.DotNet.Try.ProjectTemplate.Tutorial<\/code><\/p>\n<p>If the installation succeeds, it will print the available templates for <code>dotnet new<\/code>, including <code>trydotnet-tutorial<\/code>.<\/p>\n<p><a href=\"https:\/\/user-images.githubusercontent.com\/12554141\/59791378-cc28a700-9286-11e9-9ca4-95742e17925f.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"alignnone\" style=\"max-width: 100%;\" src=\"https:\/\/user-images.githubusercontent.com\/12554141\/59791378-cc28a700-9286-11e9-9ca4-95742e17925f.png\" alt=\"dotnet new templates\" width=\"1642\" height=\"173\" \/><\/a><\/p>\n<p>Also, you need to install the <code>dotnet try<\/code> global tool, if you haven&#8217;t already<\/p>\n<p style=\"text-align: center;\"><code>dotnet tool install -g dotnet-try<\/code><\/p>\n<h2><a id=\"user-content-using-the-template\" class=\"anchor\" href=\"#using-the-template\" aria-hidden=\"true\"><\/a>Using the template<\/h2>\n<p>Navigate to an empty directory (or create a new one). Inside that directory, execute the following command:<\/p>\n<p style=\"text-align: center;\"><code>dotnet new trydotnet-tutorial<\/code><\/p>\n<p>For example, if the directory name is &#8220;myTutorial&#8221;, it will result in the following layout:<\/p>\n<p><a href=\"https:\/\/user-images.githubusercontent.com\/12554141\/58923832-2a398400-86f6-11e9-824e-92f2635f1643.PNG\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" style=\"max-width: 100%;\" src=\"https:\/\/user-images.githubusercontent.com\/12554141\/58923832-2a398400-86f6-11e9-824e-92f2635f1643.PNG\" alt=\"Created layout\" \/><\/a>\n<b><\/b><\/p>\n<p><em><b>Tip:\u00a0<\/b>You can also use the <code>--name<\/code> option to automatically create a directory with the appropriate name.<\/em><\/p>\n<p style=\"text-align: center;\"><code>dotnet new trydotnet-tutorial --name myTutorial<\/code><\/p>\n<p><code><\/code>Now, let&#8217;s see the template in action. In the &#8220;myTutorial&#8221; directory, execute the following command:<\/p>\n<p style=\"text-align: center;\"><code>dotnet try<\/code><\/p>\n<p style=\"text-align: left;\">This will start the <code>dotnet try<\/code> tool and open a browser window with the interactive readme. You can click the &#8220;Run&#8221; button in the browser and see the output of the program. If you type in the editor you will also get live diagnostics and IntelliSense. Try modifying the code here and clicking run again to see the effect of your changes.<\/p>\n<p><a href=\"https:\/\/user-images.githubusercontent.com\/12554141\/58923846-4a694300-86f6-11e9-8848-ef675b8a5a20.gif\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" style=\"max-width: 100%;\" src=\"https:\/\/user-images.githubusercontent.com\/12554141\/58923846-4a694300-86f6-11e9-8848-ef675b8a5a20.gif\" alt=\"dotnet try in action\" \/><\/a><\/p>\n<h2><\/h2>\n<h2><a id=\"user-content-understanding-the-template\" class=\"anchor\" href=\"#understanding-the-template\" aria-hidden=\"true\"><\/a>Understanding the template<\/h2>\n<p>The files in a <code>dotnet try<\/code> tutorial will typically be of one of three categories:<\/p>\n<h3><a id=\"user-content-markdown-files\" class=\"anchor\" href=\"#markdown-files\" aria-hidden=\"true\"><\/a>Markdown files<\/h3>\n<p>These are the files that will serve as your documentation. These files will be rendered normally by other markdown engines and include special settings to enable them to be rendered interactively by the <code>dotnet try<\/code> engine.<\/p>\n<p>In <code>Readme.md<\/code>, notice that the code fences (the three tick notation (<code>&#96;&#96;&#96;<\/code>) used to denote code in markdown format) have some special arguments like <code>--source-file<\/code>, <code>--region<\/code>,\u00a0 etc and you actually don&#8217;t see any code inside the fences. However when we run <code>dotnet try<\/code>, the code fence is replaced with an interactive editor.<\/p>\n<h3><a id=\"user-content-project-file\" class=\"anchor\" href=\"#project-file\" aria-hidden=\"true\"><\/a>Project File<\/h3>\n<p><code>myTutorial.csproj<\/code> is a normal C# project file that targets .NET Core. Any NuGet packages you add to this file will be available to the users.\n<i><b><\/b><\/i><\/p>\n<p><i><b>Note:\u00a0<\/b>This project references <code>System.CommandLine.DragonFruit<\/code>. The usage is explained below.<\/i><\/p>\n<h3><a id=\"user-content-source-files\" class=\"anchor\" href=\"#source-files\" aria-hidden=\"true\"><\/a>Source Files<\/h3>\n<p>These are the files that contain the code that will be executed. For simplicity, the template has only one source file: <code>Program.cs<\/code>. However, since your project is a .NET Core project, any <code>.cs<\/code> files added to the directory will be a part of the compilation. You can also reference any of these files from a code fence in your markdown file.<\/p>\n<p>Looking at the contents of <code>Program.cs<\/code>, you will notice that instead of the familiar <code>Main(string[] args)<\/code> entry point, this program&#8217;s entry point uses the new experimental library <a href=\"https:\/\/github.com\/dotnet\/command-line-api\/wiki\/DragonFruit-overview\">System.CommandLine.DragonFruit<\/a> to parse the arguments that were specified in your Markdown file&#8217;s code fence. The <code>Readme.md<\/code> sample uses these arguments to call different methods. You&#8217;re not required to use any particular library in your backing project. The command line arguments are available if you want to respond to them, and <code>DragonFruit<\/code> is a concise option for doing so.<\/p>\n<h2><a id=\"user-content-whats-happening-behind-the-scenes\" class=\"anchor\" href=\"#whats-happening-behind-the-scenes\" aria-hidden=\"true\"><\/a>What&#8217;s happening behind the scenes<\/h2>\n<p>Code fences are a standard way to include code in your markdown files. The only change you need to make is to add a few options immediately following the <code>&#96;&#96;&#96;<\/code> in the first line of your code fence. If you notice the below code fence (excerpted from <code>Readme.md<\/code>), there are three options in use.<\/p>\n<div class=\"highlight highlight-source-gfm\">\n<pre class=\"\">```cs --source-file .\/Program.cs --project .\/myTutorial.csproj --region HelloWorld\r\n```<\/pre>\n<\/div>\n<table style=\"width: 899px;\">\n<thead>\n<tr>\n<th style=\"width: 284px;\">Option<\/th>\n<th style=\"width: 614px;\">\u00a0 What it does<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"width: 284px;\"><code>--project .\/myTutorial.csproj<\/code><\/td>\n<td style=\"width: 614px;\">Points to the project that the snippet is part of.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 284px;\"><code>--region HelloWorld<\/code><\/td>\n<td style=\"width: 614px;\">Identifies a C# code <code>#region<\/code> to focus on.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 284px;\"><code>--source-file .\/Program.cs<\/code><\/td>\n<td style=\"width: 614px;\">Points to the file where the sample code is pulled from.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>The code in <code>Program.cs<\/code> demonstrates one way to use regions. Here regions are being used to determine which method to execute as well as determining which part of the code to display in the editor.<\/p>\n<p>You&#8217;re all set! Now you can tweak and play around with the template and create your own awesome interactive tutorials.<\/p>\n<p>You can learn more or reach out to us on <a href=\"https:\/\/github.com\/dotnet\/try\">GitHub<\/a>.<\/p>\n<\/article>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In our previous post, we announced dotnet try\u00a0a global tool which allows developers to create interactive workshops and documentation. Tutorials created with dotnet try let users start learning without having to install an editor. Features like IntelliSense and live diagnostics give users a sophisticated learning and editing experience. Today, we are releasing a new dotnet [&hellip;]<\/p>\n","protected":false},"author":4909,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[685],"tags":[],"class_list":["post-23532","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet"],"acf":[],"blog_post_summary":"<p>In our previous post, we announced dotnet try\u00a0a global tool which allows developers to create interactive workshops and documentation. Tutorials created with dotnet try let users start learning without having to install an editor. Features like IntelliSense and live diagnostics give users a sophisticated learning and editing experience. Today, we are releasing a new dotnet [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/23532","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/4909"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=23532"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/23532\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=23532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=23532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=23532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}