Here is the link to the "home page" for this blog series.

We start with Azure DevOps and create a project called DotNetCore. How to create an Azure DevOps project you can read here. My project will be public, take a look. Create repo called MyVeryFirstAPI. Get the code by using Visual Studio or your favorite git tool. I prefer command line, navigate to your folder where you want to store your code (mine is C:\blog\azureDevOps\DotNetCore) and run git command

cd \blog\azureDevOps\DotNetCore
git clone https://[email protected]/sergeydotnet/DotNetCore/_git/MyVeryFirstAPI

When you have everything installed, open Visual Studio and click on File-> New Project... or use shortcut Ctrl+Shift+N

New Project

Choose ASP.NET Core Web API

Also provide Name, then Location by clicking on Browse... Don't select Place solution and project in the same directory.

Click Next

Make sure you are using the latest .NET Core version, 6.0 is the latest when I am creating this post. Skip the Authentication part for now and docker support. Choose also Enable OpenAPI support and select Use controllers. I prefer to use old way to create API and use controllers because API quickly become very big and controllers help you to organize your API.

Click Create.

Visual Studio generates following structure for us

Always check file explorer as well

Visual Studio generates MyVeryFirstAPI.sln file and the folder MyVeryFirstAPI.

Content of MyVeryFirstAPI folder looks like this

I will write later about all this files but now you have to learn about 2 most important files: MyVeryFirstAPI.sln and MyVeryFirstAPI.csproj. *.sln file, called solution file is the file that includes all information about our application and can include many *.csproj files, called project file. When you close your Visual Studio and want to continue to work further you have to navigate to *.sln file and double click on it to open your application using Visual Studio.

Now we take a look at MyVeryFirstAPI.csproj. Right click on  MyVeryFirstAPI node in the Visual Studio

Click on Edit MyVeryFirstAPI.csproj

The file looks like this

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
  </ItemGroup>

</Project>


The most important things is TargetFramework node. Here you are telling which version of .NET Core you want to use. In this case we are using 6.0. Just ignore Nullable and ImplicitUsing for now.

ItemGroup node is where you list all your NuGet packages. If you don't know about NuGet, you can read Microsoft documentation here. To explain it short: we, developers, don't like to reinvent the wheel and solve same problems again and again that's why we solve the problem, create a package like small application and use NuGet to store and distribute our solution to the all developers. NuGet is basically package manager for .NET application.

Good practice here always specify a Version to have control over the versioning. If you are not specifying a version, the latest NuGet package will be downloaded.

If you like me and prefer to use command line and do all this steps using .NET Core command-line interface (CLI) check this post.

Now we are ready to build and run solution. Remember to keep your code under source control.

git add .
git commit -m "Initial commit"
git push

Run the application by choosing first MyVeryFirstAPI, in the dropdown

and click F5 or go to Debug->Start Debugging

Start Debugging

The output looks like this in the browser

Here is the link to the "home page" for this blog series.

Let me know in the comments if you experienced any troubles or if you have any feedbacks. Don't forget to subscribe to get news from Sergey .NET directly to your mailbox.


Get started with .NET Core

My public Azure DevOps repo for this post

Create a new project Azure DevOps

An introduction to NuGet

Create first .NET Core API using .NET Core command-line interface (CLI)