iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 4
1
Microsoft Azure

Azure 的自我修煉系列 第 4

Day04 Dotnet Core 專案

Dotnet Core 介紹

DotNet Core是一個開發框架,使用C#語言,
可以拿來開發跨平台的應用程式,
網路上也很多教學可以看,大家可以多多利用。
.NET Core 文件

深入瞭解 .NET Core,這是一種開放原始碼、一般用途的開發架構,可用於建立跨平臺應用程式。

安裝 .Net Core

.NET Core 簡介

由於我是 Mac 環境,所以點選文件上的[Windows 和 macOS 的安裝程式],這邊依據自己的環境安裝
https://ithelp.ithome.com.tw/upload/images/20200902/20072651FIHxCbPySb.png

下載安裝檔,執行安裝流程,簡介
https://ithelp.ithome.com.tw/upload/images/20200902/20072651Uk90PGa4yL.png
安裝類型
https://ithelp.ithome.com.tw/upload/images/20200902/2007265196EV3OvwSr.png
安裝
https://ithelp.ithome.com.tw/upload/images/20200902/20072651dRmnpkeed1.png
安裝完成
https://ithelp.ithome.com.tw/upload/images/20200902/20072651JGceWuvwg5.png

.NET Core CLI 概觀

(CLI) 的 .NET Core 命令列介面,是用於開發、建立、執行和發佈 .NET Core 應用程式的跨平臺工具鏈。

指令說明

dotnet -h

https://ithelp.ithome.com.tw/upload/images/20200902/20072651lAo89yUsHa.png
https://ithelp.ithome.com.tw/upload/images/20200902/20072651J9G9mZyFsK.png

常用指令

指令 說明 範例
new 創建 dotnet new console
run 執行 dotnet run
build 建置 dotnet build -o build_output
publish 發布 dotnet publish -c Release -o publish_output

dotnet new 創建指令

先來看看指令說明

dotnet new -h

參數
https://ithelp.ithome.com.tw/upload/images/20200902/200726519pFSxx2DQF.png
樣板
https://ithelp.ithome.com.tw/upload/images/20200902/20072651qOehxo4ZFF.png
範例
https://ithelp.ithome.com.tw/upload/images/20200902/20072651kTDAkwTrwx.png

dotnet run 執行指令

dotnet run -h

https://ithelp.ithome.com.tw/upload/images/20200902/200726514O4E4et2Ym.png

dotnet build 建置指令

dotnet build -h

https://ithelp.ithome.com.tw/upload/images/20200902/20072651Ohlqq2Pog0.png

dotnet publish 發布指令

dotnet publish -h

https://ithelp.ithome.com.tw/upload/images/20200902/20072651oIElX5Zwrx.png

建立您的第一個應用程式

創建 console 專案

## 創建專案資料夾
mkdir console
## 切換到專案資料夾下面
cd console
## 執行創建指令
dotnet new console

https://ithelp.ithome.com.tw/upload/images/20200902/20072651FSVr9ZIhjs.png

預設會有以下幾的檔案與目錄

檔案 說明
Program.cs 主程式檔
console.csproj 專案檔
obj 專案暫存目錄

執行專案,印出 "Hello World!"

dotnet run

https://ithelp.ithome.com.tw/upload/images/20200902/20072651XEYvlNzFzY.png

執行過後目錄下會多一個/bin目錄,
這個因為run指令會先幫你build專案之後在執行專案
如果你輸入 dotnet build --output build_output
會把專案建置在 build_output 目錄,
你會發現 build_output 裡面的檔案和 bin/Debug/netcoreapp3.1 裡面一樣,
最後發布專案,以下指令大家可以玩玩看。

dotnet build -o build_output
dotnet publish -c Release -o publish_output
ls bin/Debug/netcoreapp3.1/
ls build_output
ls publish_output

https://ithelp.ithome.com.tw/upload/images/20200902/200726518JA1gONo2H.png

描述
dotnet build 命令會將專案及其相依性建置成一組二進位檔。 二進位檔會將專案的程式碼包含在副檔名為 .dll的中繼語言(IL)檔案中。 視專案類型和設定而定,可能會包含其他檔案,例如:
如果專案類型是以 .NET Core 3.0 或更新版本為目標的可執行檔,則可以用來執行應用程式。
用來以 .pdb副檔名進行偵錯工具的符號檔。
檔案上的.deps.js ,其中列出應用程式或程式庫的相依性。
檔案上的.runtimeconfig.js ,其指定應用程式的共用執行時間及其版本。
專案相依的其他程式庫(透過專案參考或 NuGet 套件參考)。

相關連結:

上一篇 Day03 Resource Group 資源群組
下一篇 Day05 MVC專案建置


上一篇
Day03 Resource Group 資源群組
下一篇
Day05 MVC 專案建置
系列文
Azure 的自我修煉30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言