Please enable Javascript to view the contents

在 Mac 上安裝 dotnet tool

· ☕ 1 分钟 · 🐔 Redd Tsai
🏷️
  • #dotnet
  • 至從開始使用 dotnet core 後,個人的開發方式也從 Visual Studio on Windows,轉換為 Visual Studio Code on Mac,轉變的過程有很多值得記錄。例如最近開發上需要安裝一個 dotnet 工具,如果是用 Visual Studio,會交由擴充管理員來安裝工具,那在沒有 Visual Studio 的協助下呢?這裡會介紹如何使用 CLI 來安裝 dotnet-ef。

    Requirements

    首先準備好環境,以我為例:

    • macOS 10.15
    • .NET Core 3.1

    環境確認後,透過以下指令,列出已安裝的 dotnet tool。

    1
    2
    
    dotnet tool list
    dotnet tool list -g
    

    Install

    透過 dotnet CLI 來安裝工具,這裡介紹安裝 dotnet-ef 工具到全域或本地。

    • Global
      1
      
      dotnet tool install dotnet-ef -g
      
    • Local
      安裝本地工具,需要定義 manifest file。首先準備好 dotnet project,在專案下執行以下命令,它會產生一個 dotnet-tools.json 記錄本地工具。
      1
      2
      
      dotnet new tool-manifest
      dotnet tool install
      

      .config/dotnet-tools.json

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      
      {
        "version": 1,
        "isRoot": true,
        "tools": {
          "dotnet-ef": {
            "version": "3.1.3",
            "commands": [
              "dotnet-ef"
            ]
          }
        }
      }
      

    Update

    更新 dotnet tool,一樣分為全域和本地,如下示範:

    • Global
      1
      
      dotnet tool update -g dotnet-ef
      
    • Local
      1
      
      dotnet tool update dotnet-ef
      

    Uninstall

    卸載已安裝的工具:

    • Global
      1
      
      dotnet tool uninstall -g dotnet-ef
      
    • Local
      1
      
      dotnet tool uninstall dotnet-ef
      

    Reference

    .NET Core tools

    分享

    蔡文杰
    作者
    Redd Tsai
    Backend Developer