- .NET Core command-line interface (CLI) tools
- ดาว์นโหลด .NET Core ได้ที่ Download .NET หรือ Download .NET Core
- ตรวจสอบเวอร์ชันของ .NET Core
- สร้างโปรเจ็กส์ด้วยคำสั่ง dotnet new
- รันโปรเจ็กส์ด้วยคำสั่ง dotnet run
- ดู info
- ติดตั้ง dotnet-ef
- อัพเดท dotnet tool
1.ตรวจสอบเวอร์ชันของ .NET Core
> dotnet --version 2.1.603
> dotnet --list-sdks 5.0.101 [C:\Program Files\dotnet\sdk]
> dotnet --list-runtimes Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
2.สร้างโปรเจ็กส์ด้วยคำสั่ง dotnet new
สร้างโปรเจ็กส์ Console application
> dotnet new console -o Console1
สร้างโปรเจ็กส์ ASP.NET Core Web App
> dotnet new webapp -o WebApp1
หรือ
> dotnet new razor -o WebApp2
สร้างโปรเจ็กส์ ASP.NET Core Web App (MVC)
> dotnet new mvc -o WebMvc1
3.รันโปรเจ็กส์ด้วยคำสั่ง dotnet run
> cd <PROJECT_FOLDER> > dotnet run
หรือถ้าจะแก้ไขหน้า Page แล้ว refresh ดูผลลัพธ์ได้เลย ให้ใช้คำสั่ง (ดู Develop ASP.NET Core apps using a file watcher)
> dotnet watch run
4.ดู info
> dotnet --info .NET Core SDK (reflecting any global.json): Version: 2.1.603 Commit: ae71c68742 Runtime Environment: OS Name: Windows OS Version: 10.0.17134 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.1.603\ Host (useful for support): Version: 2.1.10 Commit: 9013a2af4b .NET Core SDKs installed: 2.1.504 [C:\Program Files\dotnet\sdk] 2.1.505 [C:\Program Files\dotnet\sdk] 2.1.602 [C:\Program Files\dotnet\sdk] 2.1.603 [C:\Program Files\dotnet\sdk] .NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download
5.ติดตั้ง dotnet-ef
.net core 3.0 ไม่มีคำสั่งนี้มาให้
> dotnet ef migrations add Initial Could not execute because the specified command or file was not found. Possible reasons for this include: * You misspelled a built-in dotnet command. * You intended to execute a .NET Core program, but dotnet-ef does not exist. * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
ให้ติดตั้งก่อนใช้งาน ดู Entity Framework Core tools reference – .NET CLI
> dotnet tool install --global dotnet-ef You can invoke the tool using the following command: dotnet-ef Tool 'dotnet-ef' (version '3.0.0') was successfully installed.
ตรวจสอบว่าติดตั้งเรียบร้อยมั๊ย
> dotnet ef _/\__ ---==/ \\ ___ ___ |. \|\ | __|| __| | ) \\\ | _| | _| \_/ | //|\\ |___||_| / \\\/\\ Entity Framework Core .NET Command-line Tools 3.0.0
ติดตั้งแพจเกจ Microsoft.EntityFrameworkCore.Design ล่าสุด
> dotnet add package Microsoft.EntityFrameworkCore.Design
Tutorial: Using the migrations feature – ASP.NET MVC with EF Core
> dotnet ef migrations add Initial
> dotnet ef database update
6.อัพเดท dotnet tool
ถ้ารันคำสั่ง dotnet แล้วได้ข้อความ “The EF Core tools version ‘3.0.0’ is older than that of the runtime ‘3.1.2’. Update the tools for the latest features and bug fixes.” ให้ทำการอัพเดท dotnet tool ด้วยคำสั่ง
> dotnet tool update --global dotnet-ef