Okay, it's time to start getting our hands dirty, and we're going to be using the dotnet SDK to create
our dotnet projects.
Now you should have had this installed, or you should have installed this as part of the developer
setup.
And just to confirm that we do have this installed and available, we can type into the command line
dotnet info.
And this will give us the information about what dotnet SDK is and the runtimes we have installed.
Now at the time of recording then dotnet nine has just been released.
So I'm using dotnet nine and I can see that I have the.
Net nine runtime installed that I'm highlighting.
And also we have the dotnet SDK installed in my case version 9.0. 100.
Now you don't need to use exactly the same as me.
All I ask is that you use the latest stable released version of DotNet that is available as you're watching
this course.
Now let's possibly.
Net nine if you're watching it when dotnet ten has been released, then please go ahead and installed
net ten.
But please do make sure that it's a released version and not a pre-released version to guarantee maximum
opportunity for success.
So now that we've confirmed that we have Net installed, let's take a look at what we can do with the.
Net SDK.
Now we're going to use it to create a project and a.
Net SDK comes with a number of templates to help us get started.
And if we type in.
Net new list, then we can see a list of the different templates that are available that come with the
SDK.
Now we're going to be creating.
Now we're going to be creating a web API type of project this one here.
So in order to use this then we say dotnet new web API.
We'll also use another few things from inside here as well.
As we create our projects we're going to need a solution file for instance because this is a container
that contains dotnet projects one or more.
Now in our project we're only going to have a single.
Net project, but we'll still create a solution file for it, because that helps us manage our project
inside Visual Studio Code that we'll use very soon.
So let's go about the business of creating what we need inside here.
And I'll just clear my window.
And by the way, I'm operating inside an empty user folder just called demo.
If I list the contents here, then I can see it's empty on windows.
Of course, you would use dir to list the contents of the folder that you're inside of.
Please do use a user folder.
Please do not use a system folder like system32 if you're on windows, and this will ensure that your
project has the correct permissions that you need to do this with.
So let's first of all create a folder that's going to contain our code.
So I'm just going to use mkdir same command on Windows as Mac.
And I'm just going to call this project Restore.
It's a e-commerce store that's based on react I guess.
So that's the name I'm going for.
And I'm just going to CD into this new folder And I'm using the clear command because that clears my
window, obviously.
On windows, if you're in a command prompt it's going to be slightly different.
That would be CLS.
Now we want to create, first of all a new solution file.
And we can use.
Net new SLN to achieve that.
And this will take the name of the folder and give that the name of the solution file.
So I'll press return and that gets created successfully.
And if I take a look then I can see that I now have a restore dot solution file.
What we also need is a web API type of project.
So I'm going to once again say dotnet new.
This time I'm going to say web API.
And I'm going to just get the help for this because there is a switch that we need to add since dotnet
eight, I believe this was enforced.
So I'm just going to get the context help for this.
And inside here we've got a switch that we have to use.
And it tells us or the description of this is whether to use controllers instead of minimal APIs.
Now this is a training course.
Minimum APIs can be useful because they reduce the boilerplate a little bit inside the code.
But for clarity, we want controllers, the full controllers, so that we can see clearly what's going
on rather than reduce the amount of code to its bare minimum.
So we're going to use the controllers switch when we create our new project.
So I'll clear the window once again and I'm going to say dotnet new web API.
And we give it a name.
So I'm going to say dash n.
And I'm just going to call it API.
And I'm going to add the controllers switch.
Now this is going to go ahead and create that project.
And please do ensure you add this controller switch.
If you get this wrong or you miss it, you'll create a project template that's slightly different to
mine and you won't have a controllers folder.
So please do ensure that you have that available.
I'll press return and this is going to go ahead and create that.
And boom it has been created.
And one more thing to do before we proceed is we need to add our new project to the solution file.
So the way that we do that is we can use a solution based command.
So dotnet sln.
Then we can say add.
And we're going to add in by specifying API.
And then just press tab.
And this will go ahead and add our API project to our solution container.
So we're just going to do one quick test.
We're going to open up our project inside Visual Studio Code.
And one way that we can do that is by typing in code followed by a space, followed by a period, and
then pressing return.
And then this should go ahead and open up vs code.
And it's done that in another window.
So I'll just move this across inside here and we can see that we've got our folder, the restore folder
and the API and the files that are part of this new project that we have created.
Now just one thing to check before we move forward is and please ignore any pop ups you get for now,
one thing I'm going to do before I move forward is just make sure the project actually runs.
So inside VS code we do get an integrated terminal On my particular settings, I just press Ctrl and
Apostrophe to open this.
But if that's not the shortcut for yourself, please go to code and then Settings and Keyboard Shortcuts
and just search inside settings for terminal.
As you might want to change this or use something that's convenient because we do use this a lot.
And I'm going to search for toggle terminal.
Toggle is what I'm looking for here.
And it's this one here.
So this is my shortcut key which looks like it's been updated at some point because it's got a user
one.
But please use whatever it is for your version of VSCode just so that you can get to the terminal.
So inside the terminal we're just going to CD into the API folder.
We need to be inside that folder to run this specific project.
And then we can execute dotnet run press return.
And this will start our project running.
Or at least I hope that's what it's going to do.
And finally it has done.
I've just installed dotnet nine.
So maybe the first time you use it it's a little bit slower than normal.
But we can see that our application is running on localhost 5164.
And just as another quick test, let's just see what is or see what we see when we browse to this URL.
So I'm just going to paste that into Chrome.
And it looks like we get nothing.
But that's not strictly true because inside this template please ignore any warnings you see for now
as well.
Inside this template we do have something called a weather forecast controller, and I'll explain about
how the routes work and everything like that as we go along, but we're going to see if we can return
something from this controller.
The code in here basically returns a list of weather forecast summaries, and it's just some demo code
that's provided with the template.
But in order to get to this, we need to specify that we want to go to localhost whatever that port
is.
That's a randomly generated number.
So it would be different for yourself followed by weather forecast to get to the controller.
And if I press return we can see the summary that it returns from our controller endpoint there.
So if we've got to this stage we know that our API functionality is working and we could move on to
the next lesson.