{"id":23242,"date":"2019-05-16T13:01:47","date_gmt":"2019-05-16T20:01:47","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet\/?p=23242"},"modified":"2019-10-23T13:34:15","modified_gmt":"2019-10-23T20:34:15","slug":"creating-interactive-net-documentation","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/creating-interactive-net-documentation\/","title":{"rendered":"Create Interactive .NET Documentation with Try .NET"},"content":{"rendered":"<p>When it comes to developers&#8217; documentation, it is essential that we capture their interest and lead them down the path of success as soon as possible. Across multiple languages, developer ecosystems have been providing their communities with interactive documentation where users can read the docs, run code and, edit it all in one place. For the past two years, the language team has been evolving Try.NET to support interactive documentation both online and offline.<\/p>\n<h3>What is Try.NET<\/h3>\n<p>Try .NET is an interactive documentation generator for .NET Core.<\/p>\n<h2 id=\"try-net-online\">Try .NET Online<\/h2>\n<p>When Try .NET initially launched in September 2017, on <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/tutorials\/intro-to-csharp\/\">docs.microsoft.com,<\/a> we executed all our code server side using Azure Container Instances. However, over the past fives months we switched our code execution client side using Blazor and Web Assembly. You can see this for yourself by visiting <a href=\"https:\/\/docs.microsoft.com\/dotnet\/csharp\/tutorials\/intro-to-csharp\/hello-world?tutorial-step=5\">this page<\/a>, and going to the developer tools. Under the <em>Console<\/em> tab, you will see the following message <code>WASM:Initialized<\/code> now, switch over to the <em>Network<\/em> tab, you will see all the DLLs now running on the client side. <img decoding=\"async\" src=\"https:\/\/user-images.githubusercontent.com\/2546640\/57245063-c6d10f00-6fee-11e9-860e-ddd6327c79c5.PNG\" alt=\"WASm\" \/> <em>Console Tab: WASM Initialized<\/em> <img decoding=\"async\" src=\"https:\/\/user-images.githubusercontent.com\/2546640\/57245056-c3d61e80-6fee-11e9-91f3-628aaa125a1f.PNG\" alt=\"Network\" \/> <em>Network tab: DLLs<\/em><\/p>\n<h2 id=\"try-net-offline\">Try .NET Offline<\/h2>\n<p>It was essential for us to provide interactive documentation both online and offline. For our offline experience, it was crucial for us to create an experience that plugged into our content writers&#8217; current workflow. In our findings, we noticed that our content developers had two common areas they consistently used while creating developer documentation.<\/p>\n<ol>\n<li>A sample project that users could download and run.<\/li>\n<li>Markdown files with a set of instructions, and code snippets they copied and pasted from their code base. Try .NET enables .NET developers to create interactive markdown files with the use of the <\/li>\n<\/ol>\n<p><code>dotnet try<\/code> global tool. To make your markdown files interactive, you will need the <a href=\"https:\/\/dotnet.microsoft.com\/download\/dotnet-core\/3.0\">.NET Core SDK<\/a>, the <a href=\"https:\/\/www.nuget.org\/packages\/dotnet-try\/\">dotnet try global tool<\/a>, <a href=\"https:\/\/visualstudio.microsoft.com\/\">Visual Studio<\/a> \/ <a href=\"https:\/\/code.visualstudio.com\/\">VS Code<\/a>, and your repo. <img decoding=\"async\" src=\"https:\/\/user-images.githubusercontent.com\/2546640\/57158389-47a2c780-6db1-11e9-96ad-8c6e9ab52853.png\" alt=\"interactive_doc\" \/><\/p>\n<h3 id=\"how-are-we-doing-this-\">How are we doing this?<\/h3>\n<p><strong>Extending Markdown<\/strong> In markdown, you use fenced code blocks to highlight code snippets. You triple back-ticks before and after code blocks. You can add optional language identifiers to enable syntax highlighting in your fenced code block. For example, C# code block would look like this:<\/p>\n<pre class=\"lang:default decode:true\"><code class=\"lang-markdown\">``` cs \nvar name =\"Rain\";\nConsole.WriteLine($\"Hello {name.ToUpper()}!\");\n```<\/code><\/pre>\n<p>With Try .NET we have extended our code fences to include additional options.<\/p>\n<pre><code class=\"lang-markdown\">``` cs --region methods --source-file .\\myapp\\Program.cs --project .\\myapp\\myapp.csproj \nvar name =\"Rain\";\nConsole.WriteLine($\"Hello {name.ToUpper()}!\");\n```<\/code><\/pre>\n<p>We have created the following options:<\/p>\n<ul>\n<li><code>--region option<\/code> points to a C# region<\/li>\n<li><code>--source-file<\/code> option points to the program file<\/li>\n<li><code>-- project<\/code> option that points to project files plus the references to system assemblies. So, what we are doing here is accessing code from a #region named <\/li>\n<\/ul>\n<p><code>methods<\/code> in a backing project <code>myapp<\/code> and enabling you to run it within your markdown. <strong>Using #regions<\/strong> In our markdown we extended the code fence to include <code>--region option<\/code> that points to a C# region which targets a region named <code>methods<\/code>. So, your <code>Program.cs<\/code> would look like this:<\/p>\n<pre class=\"lang:c# decode:true \">using System;\n\n    namespace HelloWorld\n    {\n        class Program\n        {\n            static void Main(string[] args)\n            {\n                #region methods\n                var name =\"Rain\"\n                Console.WriteLine($\"Hello{name.ToUpper()}!\");  \n                #endregion\n            }\n        }\n    }<\/pre>\n<p><strong>dotnet try verify<\/strong> <code>dotnet try verify<\/code> is a compiler for your documentation. With this command, you can make sure that every code snippet will work and is in sync with the backing project. The goal of <code>dotnet try verify<\/code> is to validate that your documentation works as intended. By running <code>dotnet try verify<\/code> you will be able to detect markdown and compile errors. For example, if I removed a semicolon from the code snippet above and renamed the region from <code>methods<\/code> to <code>method,<\/code> I would get the following errors. <img decoding=\"async\" src=\"https:\/\/user-images.githubusercontent.com\/2546640\/57272892-67a0e800-704a-11e9-83f0-c0f2181e888e.PNG\" alt=\"dotnettryverify\" \/><\/p>\n<h3 id=\"try-the-dotnet-try-global-tool\">Try the <code>dotnet try<\/code> global tool<\/h3>\n<p><code>dotnet try<\/code> is now available for use! This is an <strong>early preview<\/strong> of the dotnet try global tool so, please check our <a href=\"https:\/\/github.com\/dotnet\/try-samples\">repository<\/a> and <a href=\"https:\/\/www.nuget.org\/packages\/dotnet-try\/\">NuGet package<\/a> for regular updates.<\/p>\n<p><strong>Getting Started<\/strong><\/p>\n<ul>\n<li>Clone the <a href=\"https:\/\/github.com\/dotnet\/try-samples\">dotnet\/try-samples<\/a> <\/li>\n<li>Install .NET Core SDK <a href=\"https:\/\/dotnet.microsoft.com\/download\/dotnet-core\/3.0\">3&#46;0<\/a> <\/li>\n<li>Go to your terminal <\/li>\n<li>Install the <a href=\"https:\/\/www.nuget.org\/packages\/dotnet-try\/\">Try .NET tools<\/a><\/li>\n<\/ul>\n<p><code>dotnet tool install --global dotnet-try --version 1.0.19266.1<\/code> Updating to the latest version of the tool is easy just run the command below <code>dotnet tool update -g dotnet-try<\/code> * Navigate to the Samples directory of this repository and, type the following <code>dotnet try<\/code>. <img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/user-images.githubusercontent.com\/2546640\/57164943-ab35f080-6dc3-11e9-8230-ee521e00e428.gif\" alt=\"dotnet try global tool\" width=\"1904\" height=\"992\" \/> * This will launch the browser. <img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/user-images.githubusercontent.com\/2546640\/57165217-737b7880-6dc4-11e9-8b4e-0e70966ac03d.gif\" alt=\"Interactive .NET documentation\" width=\"1680\" height=\"1080\" \/><\/p>\n<h3>Try .NET is now Open Source<\/h3>\n<p><strong>Try .NET source code is now on<a href=\"https:\/\/github.com\/dotnet\/try-samples\"> GitHub<\/a>!<\/strong>\u00a0 As we are still in the early stages of our development, we are unable to take any feature PRs at the moment but, we do intend to do this in the future. Please feel free to file any bugs reports under our issues. And if you have any feature suggestion, please submit them under our issues using the community suggestions label. Looking forward to seeing all the interactive .NET documentation, and workshop you create.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Try .NET is an interactive documentation generator for .NET Core. Using the dotnet try global tool you can now create interactive documentation too. This is an early preview of the dotnet try global tool so, please check our repository and NuGet package for regular updates.  <\/p>\n","protected":false},"author":3344,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[196,756],"tags":[],"class_list":["post-23242","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet-core","category-csharp"],"acf":[],"blog_post_summary":"<p>Try .NET is an interactive documentation generator for .NET Core. Using the dotnet try global tool you can now create interactive documentation too. This is an early preview of the dotnet try global tool so, please check our repository and NuGet package for regular updates.  <\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/23242","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\/3344"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=23242"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/23242\/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=23242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=23242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=23242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}