To get started with .NET Core read my previous blog here.
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@example.com/sergeydotnet/DotNetCore/_git/MyVeryFirstAPI
When you have everything installed, open Visual Studio and click on File-> New Project... or use shortcut Ctrl+Shift+N
Choose ASP.NET Core Web Application
Also provide Name, then Location by clicking on Browse... Choose also Create directory.
Choose API and make sure you are using the latest .NET Core version, 2.2 is the latest when I am creating this post. Skip the Authentication part for now and docker support.
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>netcoreapp2.2</TargetFramework> <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.App" /> <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" /> </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 2.2.
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. The exception here is Microsoft.AspNetCore.App package. Microsoft recommend to not specify the version for this package and saying: "The Microsoft.AspNetCore.App metapackage is not a traditional package that is updated from NuGet." If you are interested check out this discussion.
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 using F5 or go to Debug->Start Debugging
The output looks like this in the browser