.NET Core – Project Files
”;
In this chapter, we will discuss .NET Core project files and how you can add existing files in your project.
Let us understand a simple example in which we have some files which are already created; we have to add these files in our FirstApp project.
Here is the implementation of the Student.cs file
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace FirstApp { public class Student { public int ID { get; set; } public string LastName { get; set; } public string FirstMidName { get; set; } public DateTime EnrollmentDate { get; set; } } }
Here is the implementation of the Course.cs file.
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace FirstApp { public class Course { public int CourseID { get; set; } public string Title { get; set; } public int Credits { get; set; } } }
Let us now save these three files in your disk and the source folder of your project.
-
Now if you are familiar with .NET and this one was a traditional .NET framework console application, it is important to understand how to add these files in your project in Visual Studio.
-
You first need to drag the files to the solution explorer to copy them in your project folder, because your project needs reference to these files.
-
One of the benefits of .NET Core is the approach taken with the project file (project.json); we can just drop files into the root of our project and then these will be automatically included in our project.
-
We don’t have to manually reference files like we did in the past for traditional .NET Framework application in Visual Studio.
Let us now open the root of your project.
Let us now copy all of the three files into the root of your project.
You can now see all the files copied to the root folder.
Let us now go to Visual Studio; you will receive the following dialog box.
Click Yes to All to reload your project.
You will now that files are automatically included in your project.
”;