English 中文(简体)
.NET Core - Project Files
  • 时间:2024-11-05

.NET Core - Project Files


Previous Page Next Page  

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 { 
   pubpc class Student { 
      pubpc int ID { get; set; } 
      pubpc string LastName { get; set; } 
      pubpc string FirstMidName { get; set; } 
      pubpc 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 { 
   pubpc class Course { 
      pubpc int CourseID { get; set; } 
      pubpc string Title { get; set; } 
      pubpc int Credits { get; set; } 
   } 
}

Let us now save these three files in your disk and the source folder of your project.

Source Folder

    Now if you are famipar with .NET and this one was a traditional .NET framework console apppcation, 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 pke we did in the past for traditional .NET Framework apppcation in Visual Studio.

Let us now open the root of your project.

Root

Let us now copy all of the three files into the root of your project.

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.

Visual

Cpck Yes to All to reload your project.

Yes to all

You will now that files are automatically included in your project.

Advertisements