pac model

用於使用模型驅動應用程式的指令。

Commands

Command Description
pac model create 創建一個新的模型驅動應用程式。
pac model genpage download 從模型驅動的應用程式中拉取產生的頁面。
pac model genpage generate-types 為資料來源產生 TypeScript 架構定義
pac model genpage list 列出指定模型驅動應用程式中所有產生的頁面。
pac model genpage transpile 將帶有執行時型別的 TypeScript 檔案轉譯,用於測試與除錯
pac model genpage upload 將生成頁面上傳並發佈到模型驅動的應用程式。
pac model list 列出環境中所有模型驅動應用程式。
pac model list-languages 清單使 Dataverse 環境中的語言得以啟用。
pac model list-tables 在連接環境中列出 Dataverse 資料表。

pac model create

創建一個新的模型驅動應用程式。

所需參數 model create

--name -n

這是新型號驅動應用程式的顯示名稱。

可選參數 model create

--description -d

新款以模型為驅動的應用程式說明。

--environment -env

指定目標 Dataverse。 值可以是 Guid 或絕對 https URL。 如果未指定,則會使用為目前驗證設定檔選取的作用中組織。

--publish

建立應用程式後再發佈。

此參數不需要任何值。 這是一個開關。

--solution

解決方案:唯一名稱,可以加入應用程式。 預設為主動解決方案。

pac model create 範例

以下範例展示了常見的使用方式 pac model create

在主動環境中建立新的模型驅動應用程式

pac model create --name "Contoso Sales Hub"

建立一個帶有描述的應用程式,並將其加入解決方案,然後立即發佈

pac model create \
  --name "Contoso Sales Hub" \
  --description "Central hub for managing Contoso sales activities, accounts, and contacts." \
  --solution "ContosoSales" \
  --publish

透過提供環境網址,在特定環境中建立應用程式

pac model create \
  --name "Contoso Sales Hub" \
  --description "Central hub for managing Contoso sales activities, accounts, and contacts." \
  --environment "https://contoso.crm.dynamics.com" \
  --solution "ContosoSales" \
  --publish

Tip

pac model list 來驗證應用程式是被創建的,並取得其應用程式 ID 以便搭配其他指令使用,例如 pac model genpage upload

pac model genpage download

從模型驅動的應用程式中拉取產生的頁面。

所需參數 model genpage download

--app-id

模型驅動應用程式的 ID。

可選參數 model genpage download

--environment -env

指定目標 Dataverse。 值可以是 Guid 或絕對 https URL。 如果未指定,則會使用為目前驗證設定檔選取的作用中組織。

--output-directory -o

目錄用來儲存被拉取的頁面。 預設為目前目錄。

--page-id

要拉取的頁面識別碼清單,並用逗號分隔。

pac model genpage download 範例

以下範例展示了常見的使用方式 pac model genpage download

依照頁面 ID 下載單一生成頁面到本地資料夾進行編輯

pac model genpage download \
  --app-id "a1b2c3d4-1234-5678-abcd-000000000001" \
  --page-id "e5f6a7b8-abcd-ef01-2345-000000000010" \
  --output-directory ./pages/account-dashboard

一次下載應用程式中的所有生成頁面

pac model genpage download \
  --app-id "Contoso Sales Hub" \
  --output-directory ./pages

建立一個以頁面 ID 命名的子目錄,並寫入以下檔案

./pages/account-dashboard/
  e5f6a7b8-abcd-ef01-2345-000000000010/
    page.tsx          ← TypeScript source code
    page.js           ← Transpiled JavaScript
    RuntimeTypes.ts   ← Dataverse type definitions
    config.json       ← Page metadata
    prompt.txt        ← Original generation prompt

pac model genpage generate-types

為資料來源產生 TypeScript 架構定義

所需參數 model genpage generate-types

--data-sources

使用資料來源的逗號分隔清單(例如「帳戶、潛在客戶、聯絡人」)。

可選參數 model genpage generate-types

--environment -env

指定目標 Dataverse。 值可以是 Guid 或絕對 https URL。 如果未指定,則會使用為目前驗證設定檔選取的作用中組織。

--output-file -o

儲存產生的 TypeScript 架構檔案的路徑(預設為 RuntimeTypes.ts)

pac model genpage generate-types 範例

以下範例展示了常見的使用方式 pac model genpage generate-types

產生 TypeScript 類型

為 和 account 表格產生 TypeScript 類型contact,並寫成./src/RuntimeTypes.ts

pac model genpage generate-types \
  --data-sources "account,contact" \
  --output-file ./src/RuntimeTypes.ts

為單一資料表產生特定輸出目錄的型別

pac model genpage generate-types \
  --data-sources "opportunity" \
  --output-file ./pages/opportunity/RuntimeTypes.ts

Note

在撰寫查詢 Dataverse 資料表的頁面程式碼前,務必先執行 generate-types 。 產生的檔案包含強型別欄位名稱、外鍵欄位,以及每個資料表的列舉值。 依賴產生的型別可避免因欄位名稱拼寫錯誤或不存在而導致執行時錯誤。

pac model genpage list

列出指定模型驅動應用程式中所有產生的頁面。

所需參數 model genpage list

--app-id

模型驅動應用程式的 ID。

可選參數 model genpage list

--environment -env

指定目標 Dataverse。 值可以是 Guid 或絕對 https URL。 如果未指定,則會使用為目前驗證設定檔選取的作用中組織。

pac model genpage list 範例

以下範例展示了常見的使用方式 pac model genpage list

使用 App ID 的清單頁面

請使用其應用程式 ID 列出 Contoso Sales Hub 應用程式中的所有生成頁面:

pac model genpage list --app-id "a1b2c3d4-1234-5678-abcd-000000000001"

使用應用程式名稱的列表頁面

依應用程式名稱列出生成頁面(CLI 會自動查詢應用程式 ID):

pac model genpage list --app-id "Contoso Sales Hub"

pac model Genpage 範例輸出

Found 2 generated page(s):

  Account Dashboard
    Page ID: e5f6a7b8-abcd-ef01-2345-000000000010
    Description: Created: 2026-01-15T10:22:00Z

  Opportunity Tracker
    Page ID: e5f6a7b8-abcd-ef01-2345-000000000011
    Description: Created: 2026-02-03T14:05:00Z

pac model genpage transpile

將帶有執行時型別的 TypeScript 檔案轉譯,用於測試與除錯

所需參數 model genpage transpile

--code-file

包含頁面代碼的檔案路徑。

可選參數 model genpage transpile

--data-sources

使用資料來源的逗號分隔清單(例如「帳戶、潛在客戶、聯絡人」)。

--environment -env

指定目標 Dataverse。 值可以是 Guid 或絕對 https URL。 如果未指定,則會使用為目前驗證設定檔選取的作用中組織。

--output-file

儲存轉譯後 JavaScript 輸出的路徑(預設為 [code-file].compiled.js)

pac model genpage upload

將生成頁面上傳並發佈到模型驅動的應用程式。

所需參數 model genpage upload

--app-id

模型驅動應用程式的 ID。

--code-file

包含頁面代碼的檔案路徑。

可選參數 model genpage upload

--add-to-sitemap

將該頁面加入應用程式的網站地圖導覽。

此參數不需要任何值。 這是一個開關。

--agent-message

代理人的回覆訊息。

--agent-message-file

路徑指向包含代理回應訊息的檔案。

--compiled-code-file

包含已編譯 JavaScript 程式碼的檔案路徑。 若未提供,TypeScript 將自動轉譯為 JavaScript。

--data-sources

使用資料來源的逗號分隔清單(例如「帳戶、潛在客戶、聯絡人」)。

--environment -env

指定目標 Dataverse。 值可以是 Guid 或絕對 https URL。 如果未指定,則會使用為目前驗證設定檔選取的作用中組織。

--model

用於產生該頁面的 AI 模型(例如 'claude-3-5-sonnet-20241022')。

--name -n

頁面名稱。

--page-id

頁面的 ID 要更新。 若未提供,將建立新頁面。

--prompt

產生此頁面的使用者提示。

--prompt-file

指向包含產生此頁面的使用者提示的檔案路徑。

pac model genpage upload 範例

以下範例展示了常見的使用方式 pac model genpage upload

發佈新的生成頁面

將新的生成頁面發佈到 Contoso Sales Hub 應用程式,並將其加入應用程式網站地圖:

pac model genpage upload \
  --app-id "a1b2c3d4-1234-5678-abcd-000000000001" \
  --code-file ./pages/account-dashboard.tsx \
  --name "Account Dashboard" \
  --data-sources "account,contact" \
  --prompt "A dashboard showing Account records as interactive cards with contact count and revenue metrics." \
  --model "claude-sonnet-4-6" \
  --agent-message "Created account dashboard with card grid, revenue chart, and contact list. Uses account and contact tables." \
  --add-to-sitemap

更新現有的生成頁面

透過提供現有生成頁面的頁面 ID(省 --add-to-sitemap 略以避免產生重複的網站地圖條目):

pac model genpage upload \
  --app-id "a1b2c3d4-1234-5678-abcd-000000000001" \
  --page-id "e5f6a7b8-abcd-ef01-2345-000000000010" \
  --code-file ./pages/account-dashboard.tsx \
  --data-sources "account,contact" \
  --prompt "A dashboard showing Account records as interactive cards with contact count and revenue metrics." \
  --model "claude-sonnet-4-6" \
  --agent-message "Updated card layout to use a two-column grid; added revenue sparkline chart."

發佈使用模擬資料的頁面

發佈使用模擬資料的頁面(不含 Dataverse 表格——省略 --data-sources):

pac model genpage upload \
  --app-id "Contoso Sales Hub" \
  --code-file ./pages/welcome-screen.tsx \
  --name "Welcome" \
  --prompt "A branded welcome screen with Contoso logo, quick-action tiles, and a news feed placeholder." \
  --model "claude-sonnet-4-6" \
  --agent-message "Welcome page with static mock data. No Dataverse queries." \
  --add-to-sitemap

Tip

參數 --app-id 接受應用程式的 GUID 或顯示名稱。 如果多個應用程式共用相同顯示名稱,請使用 GUID 以避免歧義。 跑去 pac model list 查應用程式 ID。

pac model genpage upload 參數快速參照

Parameter Required Description
--app-id Yes 應用程式的 GUID 或顯示名稱。 快去 pac model list 找。
--code-file Yes 部署到原始檔案的路徑 .tsx
--name 僅限新頁面 顯示名稱會顯示在應用程式的網站地圖中。
--page-id Updates only 要替換現有頁面的 GUID。
--data-sources Dataverse pages 以逗號分隔的 Dataverse 資料表邏輯名稱列表(例如 "account,contact")。
--prompt Recommended 頁面功能的自然語言摘要。 儲存以供再生背景使用。
--model Recommended 用於產生頁面的模型 ID(例如 claude-sonnet-4-6)。
--agent-message Recommended 描述建造或改動的部分。 儲存在變更歷史紀錄中。
--add-to-sitemap 僅限新頁面 會自動將該頁面加入應用程式導覽。 更新時省略。

pac model list

列出環境中所有模型驅動應用程式。

可選參數 model list

--environment -env

指定目標 Dataverse。 值可以是 Guid 或絕對 https URL。 如果未指定,則會使用為目前驗證設定檔選取的作用中組織。

pac model list 範例

列出目前活躍環境中所有模型驅動應用程式:

pac model list

Sample output:

Found 3 model-driven app(s):

  Contoso Sales Hub
    App ID: a1b2c3d4-1234-5678-abcd-000000000001
    Unique Name: contoso_SalesHub

  Contoso Field Service
    App ID: a1b2c3d4-1234-5678-abcd-000000000002
    Unique Name: contoso_FieldService

  Contoso Customer Portal
    App ID: a1b2c3d4-1234-5678-abcd-000000000003
    Unique Name: contoso_CustomerPortal

pac model list-languages

清單使 Dataverse 環境中的語言得以啟用。

可選參數 model list-languages

--environment -env

指定目標 Dataverse。 值可以是 Guid 或絕對 https URL。 如果未指定,則會使用為目前驗證設定檔選取的作用中組織。

pac model list-tables

在連接環境中列出 Dataverse 資料表。

可選參數 model list-tables

--environment -env

指定目標 Dataverse。 值可以是 Guid 或絕對 https URL。 如果未指定,則會使用為目前驗證設定檔選取的作用中組織。

--search -s

以逗號分隔的搜尋名稱清單(與邏輯名稱、結構名稱或顯示名稱相符)。

--type -t

依表格類型篩選:「自訂」、「標準」或「全部」(預設:全部)。

See also

Microsoft Power Platform CLI 指令群組
Microsoft Power Platform CLI 概述