 Did you know that the command line is so powerful that you can actually create.NET Core projects within it? Learn more on this episode of Visual Studio Toolbox. Hey everyone, welcome to Visual Studio Toolbox. I'm your host Leslie Richardson coming to you from my very professional childhood bedroom studio. Today, I am joined by Syed Hashimi, who is a senior PM on the ASP.NET team. Welcome Syed. Hello. How's it going? Definitely happy to be here. Been on Visual Studio Toolbox a bunch of times in the past, then I always love coming out here to show the latest and greatest, so thanks very much for having me. Yeah, welcome back. Today, we're going to be talking about creating.NET Core projects in the command line, right? Yeah, that's right. What we're planning on doing is basically creating a series of videos, and the range of topics will be, we'll first start out with, how do you create projects using.NET new, and then we'll move on to using community created templates from both.NET new and Visual Studio, and then we'll move on to then start showing how to actually create templates and how to customize those for Visual Studio. This is really just the first video in that video series, and just like what you mentioned in this video, we'll be focusing on using.NET new and understanding the basics before we get started on creating our own templates here. Yeah. Exciting. Why the command line? What's the perk or why should I make a.NET Core project within the command line? Yeah, sure. I think that's a great question. If we were to rewind the clock five, six years back before there was.NET Core, there was.NET Framework, and in that world, everybody was creating and building and developing within Visual Studio itself, and I mean Visual Studio on Windows. But now with.NET Core, we live in a different world. So if you're creating a template, if you're creating a project template, and if you want to have the broad reach, you need to surface that in a way that can meet users where they're at, right? So today, users that will develop with Visual Studio 2019, or maybe with Visual Studio Code, or Visual Studio for Mac, and there's also third-party editors out there, like JetBrains Writer, and you can also customize any editors like Sublime and Nopad++ to also do development with.NET Core. So the way that we've architected this is, we have what's called the template engine, and you can think about that as being the foundation that everything would sit on. So we've got the template engine, and then sitting directly on top of that would be.NET new command line and also Visual Studio and Visual Studio for Mac. So the idea is we can create templates using the template engine, and then we can surface that in all the relevant locations, right? So if you create a template with template engine, you can get that to appear in the.NET new command line. It can also show up in Visual Studio 2019, Visual Studio for Mac, and also I believe Writer's got that extensibility as well to where it will show these kind of community created templates. So to answer the question is really, you just need to meet the users where they're at, and the people developing.NET Core applications, they're not only in Visual Studio anymore, they're in various different places. Then also, I think one kind of another benefit is creating a template with the template engine is very easy in comparison to the alternative technologies that are available out there. So that's why I would say that. Yeah. So you get the broadest reach, and then it's also easier to create and maintain your templates if you author them with the template engine. Great. Yeah. I personally enjoy using the command line, and I always forget that you can actually create a project in the command line to begin with. So can you show us how it works? That's right. Yeah. So let's go check out the terminal here. So let me get my terminal app opened up here, and I've got a helicopter flying in the background. I apologize about that. So first, I want to let's just explore .NET new, right? .NET new is delivered with the .NET SDK. So let's just go ahead and execute .NET new and see what we get out of this. So if you run .NET new, it'll go ahead and show you the various different templates that are available to be used. So here we can see I've got a mix of different things. I've got the, most of these are built-in templates, but we can also see I've got some community and custom templates installed here as well. So if I was to use this, sorry, at the bottom there's also some examples here. So let's take a look at that. So if I were to do .NET new, and then we would give it the name for the template that we want to create here, and that's what we see here in short name. So there's various different options here. Let's go ahead and explore the MVC option here. So if I was to do .NET new MVC, I could also get help that specifically, help that specific for this particular template here. So you can do .NET new, template name dash H to get the template specific help. And you can see we've got a bunch of different kind of parameters here as well. So the help will basically kind of spit out the different parameters that you've got here, and then we can kind of go from there. And there's also some common parameters here, where are we at? So those are here. So some of these that we'll be taking a look at is output, and then install we'll be looking at in the next video. And there's also a name value here. So we'll be using name and output here during this video. So this, let's go ahead and create a, let's go ahead and create a directory here. I'll say demo one, let's go ahead and go into that. If I would just wanted to create an MVC project, I can just do .NET new MVC. And then that'll go ahead and create a project right in this particular folder here. Yeah, so it creates the project and then it will call new get to restore them. Let's take a look at the contents here. So we can see I created an MVC project and it's named demo one.csproj. It got this name from the name of the folder here. So if you don't specify, if you don't specify a name, then the folder name will be used by default. So that's kind of the idea here. Let's also take a look at this demo project real quick. Or actually, sorry about that. Let's take a look at the program.cs. One thing that I want to point out to you. So the project name was demo one. So we can see that when I created this project, the namespace was customized for that project name. So now it's created demo one here. Nice. And yeah, so we'll talk a lot more about how these replacements work and all that sort of stuff and our kind of additional videos here. Yeah, so that's exactly what I'd expect if I were creating a template via Visual Studio. Yeah, that's right. That's right. And the mechanism that's used here is the same with .NET new as well as with Visual Studio. There's another way that I could do that as well. Let me pick a different template here. So we'll say web app. That's a name of another template that we have. Instead of just going into the directory itself, you can specify the directory that it should be created at. And then that will also be the name of the project. So I can say .NET new web app, My Cool Web. Gonna create that. So now that will create it into a folder that's called My Cool Web. And then if I was to go and look at the, let's just take a look at the startup.cs for this one, I guess. We'll see that the namespace for this one has also been kind of set to My Cool Web, right? And now we've got a project that builds and runs, right? So I can verify that by doing .NET build. And then we could also run this project with .NET run or we can go ahead and load this up into Visual Studio or whatever editor or IDE that users prefer here. So that was one kind of way of doing it. So we also mentioned that we would show the name option there. So let me go into this new folder, demo two. If I say .NET new, say web API. And then if I give it a name, I can say My Web API. Now that should create it in this folder, but with the name My Web API or in the folder called My Web API and then the name will be My Web API. And if I was to inspect the program or the startup or the weather forecast, we would see that that namespace has been declared appropriately as well. Let's take another look through the help real quick and see if there's any additional options here that we haven't talked about. So one was .NET new list. So let's go ahead and take a look at that real quick. .NET new dash L. So for .NET new dash L, this would just list out all the templates that have been installed here. And like I mentioned, I do have some kind of custom templates installed here. So if you see something different, then that means that I've just kind of installed something additional that you might not have on your box. Yeah, I don't recall seeing science tool on mine. Yeah, that's right. Let me kind of explain this output here. So here we've got the name of the template. This is just kind of a user friendly name. Here's the short name. So that was the name that I was using before, right? We saw MVC web app and web API and those are here. MVC web app and web API is right there. Here we can also see the language option. So let's say if I was an F sharp or a VB developer, I can take a look at this language column to tell me, you know what templates are available for that particular language as well. And then the tags are, they're just kind of categories, right? So if I was interested in a console app, I could do console. So let's do this..net new dash L dash H. So what help is available for list here? And we can see that I can filter by language and we can also filter by type here. So .net new dash L dash Lang F sharp. This should display only the F sharp templates and then similarly for VB, right? And then we can also do, I think we can also do something similar for the tags, I believe, or the type here basically. So if I was to say, Ash type console. Oh, sorry. Okay. So that one looks like it didn't. Oh, sorry about that. My bad. This is different. This is different. One thing that I forgot to mention here was, you know, in the list of templates that were kind of output here, there's a variety of different things. You know, the vast majority of these are project templates, but we do have a few item templates here, like get ignore global JSON and so on and so forth. So that's where the that's where the type filter comes in. So if I was to to list the project, I can do .net new dash L dash dash type project. And this would just show me all the project templates. If I wanted to see only the item templates or to replace the type with item there, you go back and see how can we filter on the the tag? I'm not sure if that's that might not actually be possible here to actually filter on the tags here. But but in Visual Studio, these tags will appear and you can actually filter in Visual Studio there. That is pretty sweet. I had no idea you could get all the same functionality that you normally would if you were to open Visual Studio for the first time, just in the command line. Yeah, yeah, that's right. And then, you know, one thing that I kind of forgot to mention here was, you know, everything that I showed here was was with built in templates. But you would get the same exact functionality with with custom templates as well. So forward to do .net new site web dash age. I would get the the template specific help. For that custom template that I've created here. So so you get the exact same experience, whether it's a built in template created by Microsoft or if it's a template that you created yourself or if a third party company created it, you know, you get the same exact experience here. It's not like we're special casing the Microsoft templates here. You know, we got the same exact experience all across the board. That's really cool. Makes you feel more official with the templates that you create. Yeah, definitely. And that was that was some feedback that we have received, you know, a lot over the course of the last several years was, you know, people, the template authors, they want their templates to appear in a first class way. So when we when we created .net new, we made sure to to kind of, you know, fulfill that promise. And we're also trying to do the same thing in Visual Studio and Visual Studio for Mac as well. That is exciting stuff. Yeah. So I think that's that's really about it here. You know, we kind of talked about how can we use .net new and how can we use the help system to kind of explore, you know, how to learn more about the command and also some kind of basics here. So I think that's really the that's really it for this video. And then the the next videos that follow, we'll we'll start seeing how can we install community templates and then use those in .net new as well as Visual Studio. That is some good stuff. I can't wait. And just to close out, you mentioned that you need the .net SDK for the command line functionality. So where can users go to make sure they have that installed? Oh, yeah, right. So so they can go to usually, I just go to to GitHub actually to get that. But, you know, I think the easiest way is to just do .net core download. And that'll take that'll take them to the right place here. So just .net.microsoft.com to get the the latest download of .net core. All right. Can't wait. Yeah, and yeah. Yeah. And everything that I'm showing here applies to both .net core 3.1 as well as .net core 5. Yeah. Sweet. That is very exciting. So yeah, thank you. And tune in next time when we talk more about the awesomeness you can do with .net templates and projects. So to Lynn, happy coding.