讓我們開始使用 Windows Admin Center SDK 來開發擴充功能! 在本文中,我們將介紹讓您的環境啟動並執行以建置和測試 Windows Admin Center 擴充功能的過程。
Note
對 Windows Admin Center SDK 不熟悉嗎? 深入了解 Windows Admin Center 的擴充功能
小提示
建立一個資料夾來存放所有 Windows Admin Center 的擴充功能開發檔案,以減少指令執行。
若要準備您的開發環境,請執行下列步驟:
安裝必要條件
若要開始使用 SDK 進行開發,請下載並安裝下列的必要項目:
- Windows Admin Center (GA 或預覽版)
- Visual Studio 或 Visual Studio Code
- Node.js 版本 24.18.1 (下載並安裝 LTS 版本)
- Node 封裝管理員 (6.14.5 或更新版本)
- NuGet (用於發佈延伸模組)
- Windows 版 Git(包含用於產生自簽憑證的 OpenSSL)
若要略過以 .NET 8 執行之 Windows Admin Center 版本中延伸模塊安裝期間發生的簽章驗證,您也應該將 Windows Admin Center 作業模式切換為「開發」。若要設定開發模式,您必須:
- 開啟 Windows Admin Center 實例的
appsettings.json檔案。 此專案預設可在C:\Program Files\WindowsAdminCenter\service\appsettings.json找到。 - 修改位於
OperationMode區段底下的WindowsAdminCenter/System欄位,將「生產」改為「開發」。
安裝全域依賴項
接著,使用 Node 封裝管理員 安裝或更新專案所需的相依性。 將這些相依性全域安裝,讓所有專案都能存取。
npm install -g @angular/cli@20.3.25
npm install -g gulp
npm install -g typescript
npm install -g eslint
npm install -g @microsoft/windows-admin-center-sdk@latest
Note
你可以安裝較新的版本。@angular/cli 然而,如果你安裝的版本高於 20.3.25,會在 gulp 建置階段看到警告,表示本地 CLI 版本與已安裝版本不符。
為側載做好環境準備
建立擴充功能後,你要把它側載到 Windows Admin Center 進行測試。 為此,請為您的擴充功能開發目錄執行以下一次性步驟:
- 以 管理員 身份開啟 PowerShell 並建立憑證目錄:
New-Item -ItemType Directory -Path "C:<path>\certificate" - 使用 Git 的 OpenSSL 產生自簽憑證:
& "C:\Program Files\Git\usr\bin\openssl.exe" req -x509 -newkey rsa:2048 -nodes -keyout C:\<path-to-extension-directory>\certificate\localhost.key -out C:\<path-to-extension-directory>\certificate\localhost.cert -days 365 -subj "/CN=localhost" -addext "subjectAltName=DNS:localhost" - 將新憑證匯入你的受信任根憑證:
Import-Certificate -FilePath "C:\<path-to-extension-directory>\certificate\localhost.cert" -CertStoreLocation "Cert:\LocalMachine\Root" - 以管理員身份在 Visual Studio Code 中開啟
C:\Program Files\WindowsAdminCenter\Service\appsettings.json。 - 找出
corsSites陣列,並新增側載 URL(預設連接埠為 4200)。"CorsSites": [ "https://localhost:4200" ] - 找到
CSPFrameAncestors陣列,並新增側載 URL(4200 為預設連接埠)。"CSPFrameAncestors": [ "'self'", ... existing entries ... "https://localhost:4200" ] - 儲存檔案後,透過執行以下操作重新啟動管理員 PowerShell 視窗中的 Windows Admin Center 服務:
Restart-Service WindowsAdminCenter
Important
這些說明提及用於開發和測試的自我簽署憑證。 不要在生產機器上使用自簽憑證來處理生產工作負載。
使用完全限定的網域名稱進行側載
若要透過包含您機器完全限定網域名稱(FQDN)的網址側載您的 Windows Admin Center 擴充功能,請依照以下額外設定步驟進行:
- 使用 Git 的 OpenSSL 產生一份自我簽署憑證,其中包含
localhost和 FQDN 的主體替代名稱:& "C:\Program Files\Git\usr\bin\openssl.exe" req -x509 -newkey rsa:2048 -nodes -keyout C:\<path-to-extension-directory>\certificate\localhost.key -out C:\<path-to-extension-directory>\certificate\localhost.cert -days 365 -subj "/CN=localhost" -addext "subjectAltName=DNS:localhost,DNS:<FQDN>" - 將新憑證匯入你的受信任的根憑證存放區:
Import-Certificate -FilePath "C:\<path-to-extension-directory>\certificate\localhost.cert" -CertStoreLocation "Cert:\LocalMachine\Root" - 更新
C:\Program Files\WindowsAdminCenter\Service\appsettings.json以包含 FQDN 來源的網址:"CorsSites": [ "https://localhost:4200", "https://<FQDN>:4200" ], "CSPFrameAncestors": [ "'self'", ... existing entries ... "https://localhost:4200", "https://<FQDN>:4200" ] - 儲存檔案後,透過執行以下操作重新啟動管理員 PowerShell 視窗中的 Windows Admin Center 服務:
Restart-Service WindowsAdminCenter
後續步驟
現在您的環境已準備就緒,您可以開始建立內容了。
SDK 設計工具組
請查看我們的 Windows Admin Center SDK 設計工具組! 此工具組的設計目的是要協助您使用 Windows Admin Center 樣式、控制項和頁面範本,快速模擬 PowerPoint 中的擴充功能。 開始撰寫程式碼之前,請先查看您的擴充功能在 Windows Admin Center 中的外觀!