{"id":60678,"date":"2021-01-12T07:00:25","date_gmt":"2021-01-12T15:00:25","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/devops\/?p=60678"},"modified":"2021-01-12T04:54:58","modified_gmt":"2021-01-12T12:54:58","slug":"generate-a-github-actions-workflow-with-visual-studio-or-the-dotnet-cli","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/generate-a-github-actions-workflow-with-visual-studio-or-the-dotnet-cli\/","title":{"rendered":"Generate a GitHub Actions workflow with Visual Studio or the dotnet CLI"},"content":{"rendered":"<p>It can feel like a lot to get started with <a href=\"https:\/\/github.com\/features\/actions\">GitHub Actions<\/a> or <a href=\"https:\/\/azure.microsoft.com\/services\/devops\/pipelines\/?WT.mc_id=devops-12448-dabrady\">Azure Pipelines<\/a> &#8211; it&#8217;s a whole new skillset. Because the alternatives for deployment are so easy (right-click publish for example), teams sometimes question whether implementing a pipeline is worth the effort. It might be agreed that CI\/CD is a &#8220;good thing&#8221;, but is it the most important thing right now?<\/p>\n<p>Even as a &#8220;seasoned builder-of-pipelines&#8221;, I often spend a lot of time with a failing build before it finally &#8220;goes green&#8221; and I can move on!<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/failed-builds.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/failed-builds-210x300.png\" alt=\"Failed builds are common before you get things working\" width=\"210\" height=\"300\" class=\"alignnone size-medium wp-image-60679\" srcset=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/failed-builds-210x300.png 210w, https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/failed-builds.png 459w\" sizes=\"(max-width: 210px) 100vw, 210px\" \/><\/a><\/p>\n<h2>Making it easy in Visual Studio<\/h2>\n<p>When I joined the <a href=\"https:\/\/developer.microsoft.com\/advocates\/?WT.mc_id=devops-12448-dabrady\">Cloud Advocacy team at Microsoft<\/a> as a DevOps specialist, one of my advocacy teammates was <a href=\"https:\/\/twitter.com\/timheuer\">Tim Heuer<\/a>. We had some&#8230; robust&#8230; discussions about how important a full end-to-end DevOps pipeline was. I&#8217;ve always been on the side of building a full pipeline from day 1, but especially for small projects, he was less convinced. Right-click publish worked fine for him! The learning curve was too steep for what seemed a small benefit.<\/p>\n<p>Fast-forward to today, and Tim is on the .NET team at Microsoft. One big focus of his is flattening that learning curve. His team (as well as many other teams at Microsoft) have been working hard to make it as simple as possible for .NET developer to build CI\/CD pipelines. They <em>want<\/em> people to be successful in a way that gives them all the benefits of DevOps!<\/p>\n<p>Back in September 2020, the Visual Studio team <a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/using-github-actions-in-visual-studio-is-as-easy-as-right-click-and-publish\/?WT.mc_id=devops-12448-dabrady\">announced a new feature for ASP.NET Core projects<\/a>. Essentially, it allowed Visual Studio users to right-click-publish, but rather than just pushing to prod, they&#8217;d be able to generate a GitHub Actions workflow!<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/actionsfromvs.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/actionsfromvs-1024x580.png\" alt=\"GitHub Actions from Visual Studio\" width=\"640\" height=\"363\" class=\"alignnone size-large wp-image-60680\" srcset=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/actionsfromvs-1024x580.png 1024w, https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/actionsfromvs-300x170.png 300w, https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/actionsfromvs-768x435.png 768w, https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/actionsfromvs-1536x870.png 1536w, https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/actionsfromvs-2048x1160.png 2048w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>But .NET is a true cross-platform framework now, and not everyone has (or needs) Visual Studio installed. Personally, I haven&#8217;t had Visual Studio installed on my primary machine for over a year! So while this is a great feature, it&#8217;s not one I use, and it doesn&#8217;t work for an increasing number of .NET developers.<\/p>\n<h2><code>dotnet new workflow<\/code><\/h2>\n<p>I recently came across a tweet from Tim where he submitted a pull request to a project to add a CI pipeline (definitely not the Tim I first met!) For people familiar with GitHub Actions, it was a fairly straightforward addition, but if not, that learning curve is steep! More impressive than the PR is the fact Tim&#8217;s starting point was a generated workflow using the <code>dotnet<\/code> CLI and a template he wrote!<\/p>\n<p><a href=\"https:\/\/twitter.com\/DennisCode\/status\/1346667146881843200\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/den-tim-tweet.png\" alt=\"Den Delimarsky thanking Tim Heuer for his PR\" width=\"588\" height=\"225\" class=\"alignnone size-full wp-image-60681\" srcset=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/den-tim-tweet.png 588w, https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/den-tim-tweet-300x115.png 300w\" sizes=\"(max-width: 588px) 100vw, 588px\" \/><\/a><\/p>\n<h3>How do I use it?<\/h3>\n<p>The template is fairly simple &#8211; it just creates a GitHub Actions workflow file in the correct location (assuming you run it in the root of your repository) that will build and test your .NET project. While it doesn&#8217;t do a lot on the surface, it&#8217;s perfect to get you over that steep learning curve!<\/p>\n<p><a href=\"https:\/\/www.timheuer.com\/blog\/generate-github-actions-workflow-from-cli\/\">Tim blogged about it in more detail<\/a>, but here are the basics:<\/p>\n<p>To use it, navigate to the root of your repo and type <code>dotnet new workflow<\/code> in your console of choice.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/dotnet-new-workflow.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/dotnet-new-workflow-1024x141.png\" alt=\"dotnet new workflow with instructions to install\" width=\"640\" height=\"88\" class=\"alignnone size-large wp-image-60682\" srcset=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/dotnet-new-workflow-1024x141.png 1024w, https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/dotnet-new-workflow-300x41.png 300w, https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/dotnet-new-workflow-768x106.png 768w, https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/dotnet-new-workflow.png 1094w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>If you don&#8217;t have the template installed already, you get clear instructions on how to install it. It&#8217;s a single command &#8211; <code>dotnet new -i TimHeuer.GitHubActions.Templates::1.0.4<\/code> &#8211; but the version may be different. Run that command and then <code>dotnet new workflow<\/code> again.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/dotnet-new-workflow-success.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/dotnet-new-workflow-success.png\" alt=\"dotnet new workflow\" width=\"713\" height=\"43\" class=\"alignnone size-full wp-image-60683\" srcset=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/dotnet-new-workflow-success.png 713w, https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/dotnet-new-workflow-success-300x18.png 300w\" sizes=\"(max-width: 713px) 100vw, 713px\" \/><\/a><\/p>\n<p>What you&#8217;ll get is a straightforward GitHub Actions workflow to build and test your .NET application. Keep in mind this is a starting point. It&#8217;s not going to do everything you might want, but it&#8217;s a solid base to build from.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/new-generated-workflow.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/new-generated-workflow.png\" alt=\"Your new generated workflow\" width=\"1018\" height=\"948\" class=\"alignnone size-full wp-image-60684\" srcset=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/new-generated-workflow.png 1018w, https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/new-generated-workflow-300x279.png 300w, https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/new-generated-workflow-768x715.png 768w\" sizes=\"(max-width: 1018px) 100vw, 1018px\" \/><\/a><\/p>\n<p>At time of writing there are two additional arguments you can specify: &#8211; <code>-sdk<\/code> or <code>--sdk-version<\/code> lets you choose the .NET SDK &#8211; <code>-b<\/code> or <code>--branch<\/code> lets you choose the branch that will trigger your workflow<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/arguments.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/arguments.png\" alt=\"Two arguments for dotnet new workflow\" width=\"662\" height=\"221\" class=\"alignnone size-full wp-image-60685\" srcset=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/arguments.png 662w, https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2021\/01\/arguments-300x100.png 300w\" sizes=\"(max-width: 662px) 100vw, 662px\" \/><\/a><\/p>\n<h2>More for .NET devs<\/h2>\n<p>These are just two of the blog posts Tim has written lately on using GitHub Actions for .NET. <a href=\"https:\/\/www.timheuer.com\/blog\/category\/github\">Check them out on his blog<\/a>!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s easier than ever to get started with a generated GitHub Actions workflow for your .NET project. Here are just a couple of options available to you from Visual Studio or the dotnet CLI.<\/p>\n","protected":false},"author":39350,"featured_media":60690,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[226,1],"tags":[],"class_list":["post-60678","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ci","category-devops"],"acf":[],"blog_post_summary":"<p>It&#8217;s easier than ever to get started with a generated GitHub Actions workflow for your .NET project. Here are just a couple of options available to you from Visual Studio or the dotnet CLI.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/60678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/39350"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=60678"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/60678\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/60690"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=60678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=60678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=60678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}