dotnet CLI 指令

.Net Core

常用dotnet指令,專門檢查AP端或Server端版本資訊

//help 資訊
dotnet --help
dotnet -h

//--version版本資訊
dotnet --version

//sdk版本資訊
dotnet --list-sdks

//Runtimes 
dotnet --list-runtimes

//Info
dotnet --info

建立dotnet new

// create sln
dotnet new sln

// create empty asp.net core project 
dotnet new web

//create asp.net core mvc project
dotnet new mvc

//mvc project. Individual validation
dotnet new mvc --auth Individual

//Create Razor Pages Projects
dotnet new page

//Create Razor Project
dotnet new blazorserver

//Create Web API Project
dotnet new webapi

//create Asp.net core gRPC Service Project
dotnet new grpc

//Create asp.net Core With Angular Project
dotnet new angular

//.gitgnore file
dotnet new gitignore

//global.json 
dotnet new globaljson

//Unit Test Project
dotnet new mstest 
dotnet new nunit
dotnet new xunit

建立Console專案測試
 

md ConsoleApp1     //建立專案目錄
cd ConsoleApp1     //移至專案目錄
dotnet new console   //建立專案
dotnet build         //建置專案
dotnet run           //專案執行

加快成立專案執行

dotnet new console -o ConsoleApp2

建立Web專案測試 

mkdir mvcapp1
cd mvcapp1
dotnet new mvc
dotnet build
dotnet run

當出現port 5000,port 5001 打瀏覽器localhost:5000可以跑

dotnet new mvc -o mvcapp3  //比較快指令

基本命令 

//初始化專案範本
dotnet new 


//還原程式相依性
dotnet restore

//建置net core程式
dotnet build

//發行程式相依性到資料夾
dotnet publish

//從原始檔執行應用程式
dotnet run

//使用測試執行程式
dotnet test

//執行VSTest.Console執行自動化測試
dotnet vstest

//建立程式碼的Nuget套件
dotnet pack

//將Preview 2 .net core 專案
dotnet migrate 

//清除組件輸出
dotnet clean 

//在方案檔案中新增或移除 列出專案選項
dotnet sln 

//顯示命令help 說明
dotnet help

//執行階段存放區中儲存組件
dotnet store 

//提供對ms build commnad line access
dotnet msbuild 


dotnet CLI 指令-專案修改命令

//專案新增nuget指令
dotnet add package

//專案移除nuget指令
dotnet remove package 

//專案列出Nuget套件
dotnet list package

//專案新增參考
dotnet add reference 

//專案移除參考
dotnet remove reference

//列出專案參考
dotnet list reference

接者來下安裝json套件

dotnet add package newtonsoft.json --version 12.0.1

如果要移除的話

dotnet remove package newtonsoft.json



dotnet CLI 指令-nuget管理命令

//新增NuGet來源
dotnet nuget add

//從伺服器刪除或取消列出套件
dotnet nuget delete

//停用Nuget來源
dotnet nuget disbale

//啟用Nuget來源
dotnet nuget enable

//列出NuGet來源
dotnet nuget list 

//清除或列出本機Nuget資源
dotnet nuget locals

//將套件push到伺服器發行
dotnet nuget push

//移除NuGet來源
dotnet nuget remove

//更新NuGet來源
dotnet nuget update

 列出NuGet來源

dotnet nuget list source

列出本機所有NuGet位置

dotnet nuget locals all -l

清除本機所有位置的Nuget資料檔

dotnet nuget locals all -c

工具管理命令

//安裝全域或本機工具,本機會新增至資訊清單,並會還原
dotnet tool install 

//列出已安裝全域或本機的工具
dotnet tool list

//更新全域工具
dotnet tool update

//還原本機工具至資訊清單中所定義工具
dotnet tool restore 

//執行本機工具
dotnet tool run

//將通用工具移除
dotnet tool uninstall 


dotnet  tool install 安裝工具

dotnet tool install --global dotnet-aspnet-codegenerator

 dotnet tool install --global microsoft.web.librarymanager.cli

dotnet tool install --global dotnet-ef

 

 dotnet tool update --global dotnet-ef

 列出已安裝全域工具

dotnet tool list -g

其他命令

dev-certs  //建立及管理開發憑證

ef  //ef core命令管理工具

sql-cache //sql server 快取管理工具

user-secrets //管理開發使用者秘密

watch //啟動會在檔案變更時執行命令的檔案監看頁

dotnet-install scripts //執行script 進行非管理 .net core sdk and shored runtime

asp.net core https 開發憑證

dotnet dev-certs https --trust

dotnet ef core

dotnet ef migrations add xxx //create migration file

dotnet ef database update // update database
//dotnet user-secrets command line

dotnet user-secrets init   //init user account pwd
dotnet user-secrets set "Azure:ServiceApiKey","abc.123"  //setting user account pwd

常用指令部分

dotnet build -h

//建置輸出檔案目錄底下
dotnet build 

//希望輸出的release
dotnet build -c release


 

//建置時可以指定Runtime Identifier
dotnet build -r win10-x64

 


//多個選項合併使用
dotnet build -r osx.10.13-x64 -c release


dotnet dlean             //clean all debug and release
dotnet clean -c debug    // clean debug
dotnet clean -c release  // clean release

註記:現在.net core 2.x sdk指令 不太需要dotnet restore了,以下執行命令都會隱含dot restore

  • dotnet new 
  • dotnet build 
  • dotnet build-server
  • dotnet run
  • dotnet test
  • dotnet publish
  • dotnet pack
dotnet run

dotnet build //建置專案

dotnet publish -c release //發布應用程式

 

老E隨手寫