Missing Document Title
theme: Next, 1
Before we can write code in
C#we must create a project.
Each project will be in its own directory.
We should create these projects in an organized parent folder such as
sdgin our home directory
.NET provides a tool for creating new projects!
- This command creates new projects from a template
- Includes starter code for us!
- We'll be using it A LOT
- In your shell change to the directory where you are going to keep your projects.
- Good options:
sdgdirectory in home folder
sdgdirectory on your desktop
sdgdirectory in your Documents folder
- Or name the directory
dev; but do keep all your projects together in a folder.
- Use the dotnet tool to create our application
dotnet new sdg-console -o OurDotnetApp
# command action template output project-name# | | | | |# v v v v vdotnet new sdg-console -o OurDotnetApp
We need to change directory into the newly created directory
Now we can open our project in our editor!
Let's see what files appear in our folder.
├── Program.cs└── OurDotnetApp.csproj
We may also see an
obj folder but we will ignore that for a moment.
^ There are two files in our folder. The first,
OurDotnetApp.csproj is a
dotnet wrote for us. It contains details about the project itself
such as which version of
dotnet our program needs. For the most part, we are
not going to modify this file
Program.cs prints out the phrase
Welcome to C#.
dotnet to run our program and see if the phrase appears on our screen we will use the
dotnet run command.
We should see the following output on the screen if everything is correct:
Welcome to C#
Now as we change our code and add more functionality we can return to our terminal/Powershell and run
dotnet run again to see our new code in action.
We can also use the
dotnet command to keep track of our code and run it every time we save our code!
dotnet watch run
dotnet watch runwatch : StartedWelcome to C#watch : Exitedwatch : Waiting for a file to change before restarting dotnet...
^ If you find yourself in a cycle of:
^ - Change code
^ - Run
^ - See output
^ - Repeat