DevQuestions with Tim Corey
I am Tim Corey. I teach coding online and my inbox is full of questions from current and future developers. I wish I could sit down with each of you and share the answers I know will help you go further, faster in the world of development. This podcast is the next best thing. On this podcast, I will answer the biggest questions people are asking! Send us to your suggestion for a future Dev Questions at https://suggestions.iamtimcorey.com/ To keep the podcast coming, like, subscribe, rate, and share it with your friends and colleagues. See why thousands of students have chosen to learn to think and code like a professional developer at www.DevForge.com.
DevQuestions with Tim Corey
131 Do I Need to Learn the .NET Command Line?
Use Left/Right to seek, Home/End to jump to start or end. Hold shift to jump forward or backward.
Do I need to learn the .NET Command Line Interface (CLI) if I use Visual Studio? Is there a benefit to knowing how to use the CLI? These are the questions we will answer in today's episode of Dev Questions.
Website: https://www.DevForge.com/
Ask Your Question: https://suggestions.iamtimcorey.com/
Sign Up to Get More Great Developer Content in Your Inbox: https://signup.iamtimcorey.com/
Welcome to the Dev Questions Podcast with Tim Corey. Join us each episode as we tackle the questions you are asking about a career in software development, understanding the industry, and new technology. If you're just starting out or you want to grow stronger as a developer, this is the place to get your questions answered. Now, here's your host, expert developer and online educator, Tim Corey.
SPEAKER_02Do I need to know the.NET command line interface or CLI? Is it important? Spoiler alert, yes. But we'll get to that in today's episode of DevQuestions. Notice the question was asked on a suggestion site. And if you have a suggestion, go to suggestions.imtimcorey.com, ask it there, and hopefully you'll see your suggestion answered in a future episode of DevQuestions. Okay, so why is a.NET command line so important? What's the reason why I should know this when I have full Visual Studio? So let's talk first about the benefits of the command line. Because if there's no benefits, why bother? And if you know the benefits, it helps you identify is it important to have these benefits? So the first benefit is it's fast. It's very, very fast. So when you are creating a new.NET gitignore file, so you use git for your source control, and you need to create a file that ignores all the Visual Studio kind of user stuff and the hidden stuff and the DLLs and exes and other things that shouldn't be committed to git. So you create a gitignore file. And that gitignore file has for.NET and for C sharp, has probably 50 or 100 lines of things it needs to properly take care of. Well, you don't want to create that by hand, right? And in Visual Studio, there is a way to go into the git settings and create a gitignore file and add it. But you kind of have to know where that is. And it's not just as simple as saying, just do it. You've got to go find that place in Visual Studio to create it. Or you can go to the command line and say.NET Add Gitignore, and you're done. It's just that simple. So there's a a lot of different commands like that where it's very, very fast to create something that you want. If you want to create a new command line app uh project, it's.NET uh.NET Add uh command line, I think it's or console. Uh it's been a little bit. Um, but you know, it's it's like three or four uh sentences or yes, three or four words. How about that? Three or four words, and you're done. And it's very, very quick. You add it, you're done. The more you do it, the more uh repetition you have in your brain, the faster and easier it is to recall. And command line now has the ability to do autocomplete. So it's even easier sometimes. So really quick. And if you need to do something really quick, it's often quicker to do it via command line than it is to go through the GUI. So when it comes to adding packages, usually you'll see whenever it says, okay, add this NuGet package, they say the package is named, let's say Dapper. And you can go find that by right-clicking on your on your references and saying NuGet packages, and then going to find NuGet packages and typing Dapper in, find the right one, clicking on it, hit install. Or they'll give you just that one line, which is.NET Add Package Dapper, I think it is called. And that'll be it. And you're done. So very, very fast for certain tasks. And so it can cut down on the amount of time it takes to do something. So there is a speed element that it brings to the table. And that's one of the benefits of the command line. Another is it's simple. There's not a lot of complexity around it. The IDE or Visual Studio is changing a lot. And we've had numerous changes over the years where you kind of move things around. And hopefully those moves are to better serve us. But sometimes it feels like we kind of lose some things in that transition where we have to go find where those things are now. Whether it's the different options for adding a project, whether it's you know, it's one project template versus multiple, those kind of things change over time and it can be complex at sometimes to know all the steps to go through. Whereas if you are reading through a blog post and it says, just run this line and it will create the same template with all the options that I have. It's a whole lot simpler than step one, step two, step three, step four, and step five in your GUI. So it's also simple. And so those are the first two benefits, but there's another benefit that is often missed, and that is it's consistent across operating systems. So if you want to create a new Blazor server project with top-level statements, where you maybe have a couple of options in there that you want to set up. Maybe you want to have individual authentication, maybe you want to have it for.NET 6 instead of.NET 7. That's a whole lot of different checkboxes and changes in your GUI. But those checkboxes and changes will be different on VS for Mac. And you don't even have that option on Linux. So there's three different ways to do that if you're on three different operating systems and trying to use Visual Studio. Whereas if you use the command line, it will be the same command line or very, very similar if you have slash differences, but the same command line for Windows, for Mac, and for Linux. So all of a sudden you have consistency in your setup. So there's some three benefits of the.NET command line. And maybe you're saying, well, I'm just not convinced yet. So let's talk about when you need the command line. There are times when it's your option. There's not really other options for you. And the first option I've already mentioned is if you're not using Visual Studio or Visual Studio for Mac. So let's say you're on Windows, but you don't have Visual Studio installed, but you want to create a quick project. How would you do that? I mean, you don't want to install what 17, 20 gigabytes worth of Visual Studio just to spin up a new console app, right? So what do you do? Well, you use the command line. That's a very, very quick and easy way of doing that on any machine that has the.NET SDK installed. If you don't have the.NET SDK installed, that's a really small download comparative to full Visual Studio. So the same is true if you're on Mac. If you have the SDK installed, you just use the command line if you don't have VS for Mac installed. Now, the next time when you need the command line is if you're on Linux. Linux does not have a dedicated IDE like Visual Studio that has those GUI steps for creating a new project or setting things up and so on. You need the command line there. So you're kind of focused on you, yes, you have to use the.NET CLI if you're on Linux. Now, this third one is one that gets missed often, and it's one that's really important. It's if you're in a build system. So if you were trying to set up CICD, where your C sharp application gets built automatically, gets integrated with the rest of the changes of your whole team, those things get tested and verified, and then maybe even deployed to some type of environment automatically. You have to know about the.NET CLI. Because I'm using CLI here for command line interface, because that's a shortened version. I want to make sure I was clear on that. So you have to know these commands because that's the only way you can call these. You can't tell a build system, okay, I want you to open up Visual Studio and click next. I want you to click new project, I want you to click on Blazorser. It's not going to do that. You need to have that command line interface in order to tell it what to do. And that ties in with a fourth time that you really need to have the.NET CLI, and that is anytime you want to automate anything. If you want to automate builds, or if you want to automate testing, or if you want to automate anything else with your C Sharp application, not in your application, but on your application. So, you know, building your application, um, testing it using unit tests, those kind of things, those type of jobs need to be done in automated fashion. And that can only be done through the.NET CLI, or practically only. You could probably set up some kind of weird uh clicking thing where it clicks on the right things in Visual Studio, but that's that'd be horrible. Okay. So those last two are kind of connected there. If you want to automate something, you have to have a CLI, and your build system uses automation. So you kind of need to have a.NET CLI. So knowing how to use a.NET CLI is pretty important because it's important that you do set up a CI CD process. It's important that you do have some testing that you run automatically to verify your application is passing all the checks and making sure that it works the way you expect it to. So is it going to benefit you to know the CLI as a developer? Absolutely. And one of the things I encourage, and it's something that you may have seen, I did a video for.NET Conf, and you may have seen that, uh, where I did VS Code for C sharp developers. And I talk about using VS Code. And sometimes that blows people's mind. They're like, I'm on Windows. Why wouldn't I just use Visual Studio? Well, there are some reasons not to. And one of them is maybe your computer isn't the fastest. And you know, it kind of slows down when you use Visual Studio with your big project and VS Code be faster. So that's one reason. But another reason is because you want to improve your C sharp skills. I would I encourage everyone, that's why I did this video. I encouraged everyone to at least one week a month or one week every two months, get into VS Code and work with your C sharp application. Build it there, run it there, test it there, develop there, because it's going to push you forward as a C sharp developer. Visual Studio holds your hand a lot. So when you create a new class, you never actually create the setup for your new class. It's all done for you with a template. And when you do other things, templates do it for you. And VS Code doesn't do all of that for you. Sometimes you have to do some of it by yourself. And when you do that, you go, wait, what? How do I structure a C sharp class? And if you don't know that off the top of your head, you probably should. And so this just forces you to go, yeah, I know how to do that. You just do, you know, namespace in the namespace, and then public class, class name, curly braces, we're good to go. Okay. And you're like, I got that. And but that little bit of practice, going back to the basics, will just strengthen your core C sharp knowledge. And sometimes doing that can really open your eyes to the things that you just kind of glossed over and you assume you know, but you don't really. So I think there's also a case for just it's good for you. But coming back to the.NET CLI, because you'll have to use that if you use VS Code, coming back to that, I think it's important because, especially of the build system, when you already use a.NET CLI and know how to do so locally before you get into setting up your CI CD process. When you know how to do it before then, you are confident in the commands you tell your CI CD system. But if the first time that you decide to use or learn a CLI is when you're setting up your build server and you have to, you're looking at this YAML document potentially, um, or the classic editor if you're in uh Azure DevOps. If you're looking at that and saying, what command do I run to build this thing? And you kind of guess at it. Well, usually, now there are local tools, and we'll get into that in a future episode of pray a Monday video. But there are some tools that run it locally, but really what you do is you commit that code to Git, you push up to GitHub, and you watch the action fire off and go, yeah, that didn't work after five minutes of waiting. And then you come back and try it again. And then you push it back up and go, that didn't work, and you push, you know, change it and push up again. Okay, that worked. You just wasted 15, 20, 30 minutes of your time tinkering around with a command line because you're learning it and trying to use it for the first time in production in a really what is a slow check environment. So by having already learned the CLI, you'll save yourself some time there. But again, you'll save yourself some time if you know, hey, I can shortcut Agnes Nougat package instead of going my references and going to find the NuGet GUI GUI and searching for the thing, and I can just say.NET Add package. Well, that's that's a whole lot faster and it speeds up your development time. And all of a sudden you're focused on the actual code instead of focused in on all these things that you don't have to. So knowing a CLI, yes, I think it's important. Do you have to know a CLI? No. No, you don't. And you can be a C sharp developer doing great C sharp work, only knowing Visual Studio for Windows. That's that is okay. You can be that, and it's okay that you're there. But I would encourage you, when the time is right, round your skills out. Become a more well-rounded C sharp developer, be more valuable in the build process. Maybe you're not even in control of the build process. You can't be. Well, you can still have some skills to offer that will allow you to expand your role in the future or offer some advice in the future. And all of a sudden, now you're more valuable as an employee because you have rounded out your skills. So I would encourage you that, okay, maybe this is not the first thing you learn, but at some point in the future, I would encourage you to learn the.NET CLI. Learn how it works, use it for a while, grow and expand your C Sharp skills, expand your skills around C Sharp and what it can do. I think that you'll find there's a lot of benefits to it. All right, so that's my answer to the question. Hopefully it answered your question. Thanks for listening. And as always, I am Tim Corey.
SPEAKER_01Thank you for joining us for this episode of Dev Questions. Tim is committed to making it easier for you to become a developer. If you would like to help make more content like this possible, please like, subscribe, rate, and share Dev Questions. You can also send your questions to questions at IamtimCore.com. Until next time, remember, you are too smart and your time too valuable to waste it making all the mistakes Tim did. When you're ready to learn to think and code like a professional developer, head over to imtimcore.com and enroll in a course.