.NET Core 示例项目教程
1. 项目的目录结构及介绍
netcore-samples/
├── ASPNET-MVC/
├── ASPNET-WebApi/
├── ConfigurationFile/
├── EnvironmentVariables/
├── HelloWorld/
├── HelloWorld-Web/
├── MultiPlatform/
├── SQLServer/
├── Web-CustomBinding/
├── Web-CustomBinding-WebListener(Win-ONLY)/
├── Encodings/
├── EmbeddedResource/
├── Thread-Process/
└── EntityFramework/
- ASPNET-MVC: 展示如何在.NET Core中创建ASP.NET MVC应用程序。
- ASPNET-WebApi: 展示如何在.NET Core中创建ASP.NET Web API应用程序。
- ConfigurationFile: 展示如何在.NET Core中使用JSON/XML/INI配置文件。
- EnvironmentVariables: 展示不同平台间环境变量的差异。
- HelloWorld: 展示如何在.NET Core中创建第一个Hello World应用程序。
- HelloWorld-Web: 展示如何在.NET Core中创建一个简单的Web应用程序。
- MultiPlatform: 展示如何在发布时针对多个平台。
- SQLServer: 展示如何在.NET Core中连接到SQL Server。
- Web-CustomBinding: 展示如何在Web应用程序中绑定多个URL。
- Web-CustomBinding-WebListener(Win-ONLY): 展示如何在Web应用程序中绑定不同的/多个主机,仅在Windows下运行。
- Encodings: 展示.NET Core中支持的编码。
- EmbeddedResource: 展示如何在.NET Core中嵌入和读取资源。
- Thread-Process: 展示如何在.NET Core中获取进程和线程。
- EntityFramework: 展示如何在.NET Core中使用Entity Framework。
2. 项目的启动文件介绍
每个项目目录中都有一个Program.cs
文件,这是项目的启动文件。例如,在HelloWorld
项目中:
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
这个文件定义了应用程序的入口点,即Main
方法。
3. 项目的配置文件介绍
在ConfigurationFile
项目中,展示了如何在.NET Core中使用配置文件。项目中包含以下配置文件:
appsettings.json
appsettings.xml
appsettings.ini
例如,appsettings.json
文件内容如下:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
这个文件定义了应用程序的日志级别和允许的主机。
以上是基于https://github.com/XiaoFaye/netcore-samples.git
项目的教程,涵盖了项目的目录结构、启动文件和配置文件的介绍。希望对你有所帮助!