Asp.net core 学习笔记 dotnet & azure 常用 command
更新: 2021-08-26
最近试了一下 vs 2022 结果 .net cli 也自动升级到 .net 6 preview 版本, 害我 dotnet new 的时候出来一个 .net 6 template... 不会玩
所以需要指定 version
Select the .NET version to use
dotnet new 选 framework version
dotnet new webapp --framework "net5.0" -o SimpleTestEFCore
因为很少用, 容易忘记所以记入起来, 方便找
Start, Run, Publish Project
dotnet new webapp -o SimpleTest (razor page project)
dotnet new web -o SimpleTest (empty project)
dotnet dev-certs https --trust (弄一次就可以了)
dotnet watch run --project ProjectName
dotnet publish Project.csproj -o C:\keatkeat\projects\release (-o 是 output path, csproj 是需要选一个)
注: publish 不会自动把 folder 里面的 files 清除哦, 在 Visual Studio 有一个选项是 delete existing files, 但是 CLI 却没用,
只能自己加 command. 停麻烦的. (/S 表示递归 subfolder)
del /S C:\Path\to\directory\*
add, list package
dotnet add ProjectName package Azure.Storage.Blobs
dotnet list ProjectName package
dotnet list package --outdated
批量 update : stackoverflow – How do I update all NuGet packages at once with the dotnet CLI?
用 VS Code NuGet Package Manager GUI
User Secret
dotnet user-secrets init --project ProjectName
dotnet user-secrets set "password" "123456"
dotnet user-secrets list
dotnet user-secrets remove "password"
dotnet user-secrets clear
Ef core
dotnet tool update dotnet-ef --global
dotnet ef migrations add init -c ApplicationDbContext -o Migrations/App
dotnet ef migrations add adjust68 -c ApplicationDbContext -o Migrations/App
dotnet ef database update -c ApplicationDbContext
dotnet ef migrations remove -c ApplicationDbContext
Azure key-vault and secret
az group create --name "klc-resource-group" --location "SoutheastAsia"
az keyvault create --name "klc-test-key-vault" --resource-group "klc-resource-group" --location "Southeast Asia"
az keyvault secret set --vault-name "klc-test-key-vault" --name "Password" --value "123456"