07 – .NET Core Console Application – Command Line Arguments

So you launch an application from the command line and there are times when you want to include parameters better known as arguments to change the behavior of your app.

Let start by right-clicking on the project and selecting properties. We’ll go into the Debug Tab and add a few arguments to the application. These arguments will be passed in when it’s launched in debug mode.

Next we’ll go into the Program.cs file and add a call to [configuration.AddCommandLine] and pass in the arguments.

Now to access those arguments we’ll go into the Worker.cs file to add some code that will logged them out to the console when we run it.

We’ll go ahead and launch the console application in debug mode…

Low & behold!!! We have the values of the arguments that were passed in via the command line.

In the next video we’ll talk about Injecting custom objects.