准备开发环境

让我们开始使用 Windows Admin Center SDK 开发扩展! 在本文档中,我们将介绍启动并运行环境以构建并测试 Windows Admin Center 的扩展的流程。

Note

Windows Admin Center SDK 新手? 了解有关 Windows Admin Center 的扩展 的详细信息

小窍门

创建一个文件夹来存储所有 Windows Admin Center 扩展开发文件,以减少命令执行。

要准备开发环境,请执行以下步骤:

安装先决条件

要开始使用 SDK 进行开发,请下载并安装以下必备组件:

若要绕过使用 .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进行测试。 为此,请为您的扩展开发目录执行以下一次性步骤:

  1. 以 管理员 身份打开PowerShell并创建一个证书目录:
    New-Item -ItemType Directory -Path "C:<path>\certificate"
    
  2. 通过使用 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"
    
  3. 将新证书导入受信任的根中:
     Import-Certificate -FilePath "C:\<path-to-extension-directory>\certificate\localhost.cert" -CertStoreLocation "Cert:\LocalMachine\Root"
    
  4. 以管理员身份在Visual Studio Code中打开C:\Program Files\WindowsAdminCenter\Service\appsettings.json。
  5. 找到 corsSites 数组,并添加旁加载 URL(端口 4200 为默认值)。
     "CorsSites": [
       "https://localhost:4200"
     ]
    
  6. 找到 CSPFrameAncestors 数组,并添加旁加载 URL(默认端口为 4200)。
     "CSPFrameAncestors": [
       "'self'",
       ... existing entries ...
       "https://localhost:4200"
     ]
    
  7. 保存文件后,在管理员的PowerShell窗口中通过以下方式重启Windows Admin Center服务:
      Restart-Service WindowsAdminCenter
    

Important

这些说明参考了开发和测试所需的自签名证书。 不要在生产机器上使用自签名证书来处理生产工作负载。

使用完全限定域名进行旁加载

若要通过包含机器完全限定域名(FQDN)的 URL 来旁加载 Windows Admin Center 扩展,请遵循以下额外的配置步骤:

  1. 使用 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>"
    
  2. 将新证书导入受信任的根中:
     Import-Certificate -FilePath "C:\<path-to-extension-directory>\certificate\localhost.cert" -CertStoreLocation "Cert:\LocalMachine\Root"
    
  3. 更新 C:\Program Files\WindowsAdminCenter\Service\appsettings.json,使其包含源为 FQDN 的 URL:
     "CorsSites": [
       "https://localhost:4200",
       "https://<FQDN>:4200"
     ],
     "CSPFrameAncestors": [
       "'self'",
       ... existing entries ...
       "https://localhost:4200",
       "https://<FQDN>:4200"
     ]
    
  4. 保存文件后,在管理员的PowerShell窗口中通过以下方式重启Windows Admin Center服务:
      Restart-Service WindowsAdminCenter
    

后续步骤

现在你的环境已准备就绪,可以开始创建内容了。

SDK 设计工具包

查看我们的 Windows Admin Center SDK 设计工具包! 此工具包旨在帮助您使用 Windows Admin Center 样式、控件和页面模板在 PowerPoint 中快速模拟扩展。 在开始编写代码之前,请先在 Windows Admin Center 中查看你的扩展!