編集

WinGet Configuration、DSCとYAMLによる宣言的開発環境セットアップ

手作業の winget install の繰り返しに代わり、開発環境を YAML で宣言し、winget configure -f で一括適用する流れが、Microsoft の開発者向けブログで紹介されている。事前要件として、管理者 PowerShell で Microsoft.WinGet.DSC モジュールを Install-Module で入れたうえで設定ファイルを渡す。設定は idempotent で、既に入っているパッケージはスキップする。自動化では --accept-configuration-agreements で確認プロンプトを省略可能。

winget import / export がパッケージ一覧のバッチインストールに留まるのに対し、winget configure は Windows 設定、Developer Mode、Visual Studio ワークロード、環境変数、リソース間の依存関係、OS 要件の事前チェック(assertions)、PowerShell DSC リソースまで扱える。assertions で例えば最小 OS ビルドを指定し、失敗時は途中で止めてメッセージを返す。dependsOn でインストール順を制御。現状のマシン状態を取り出す winget configure export--all--package-id 指定)や、リポジトリに .config/configuration.winget を置いてクローン後に同じコマンドを回す運用も紹介。GitHub Copilot CLI を設定に含めたうえで、プロンプトから設定 YAML を生成・既存スクリプトの変換・設定内容の説明に使う例も触れている。

出典記事および Microsoft Learn の WinGet Configuration ドキュメントで扱う、スキーマ https://aka.ms/configuration-dsc-schema/0.2configurationVersion: 0.2.0 を前提とした記述例。リポジトリ直下の dev-setup.winget から適用する最小例、Windows 設定リソース、assertionsdependsOn による Visual Studio ワークロードの順序付け。

初回の宣言ファイル(記事掲載例に準拠)。

yaml
# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
properties:
  configurationVersion: 0.2.0
  resources:
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      directives:
        description: Install Visual Studio Code Insiders
        securityContext: elevated
      settings:
        id: Microsoft.VisualStudioCode.Insiders
        source: winget

    - resource: Microsoft.WinGet.DSC/WinGetPackage
      directives:
        description: Install Git
        securityContext: elevated
      settings:
        id: Git.Git
        source: winget

    - resource: Microsoft.WinGet.DSC/WinGetPackage
      directives:
        description: Install Node.js LTS
        securityContext: elevated
      settings:
        id: OpenJS.NodeJS.LTS
        source: winget

    - resource: Microsoft.WinGet.DSC/WinGetPackage
      directives:
        description: Install Windows Terminal Preview
      settings:
        id: Microsoft.WindowsTerminal.Preview
        source: winget

properties.resources 配下に追加する Windows 設定(Developer Mode とダークモード)。

yaml
- resource: Microsoft.Windows.Settings/WindowsSettings
  directives:
    description: Enable Developer Mode
    allowPrerelease: true
    securityContext: elevated
  settings:
    DeveloperMode: true

- resource: Microsoft.Windows.Developer/EnableDarkMode
  directives:
    description: Enable dark mode
    allowPrerelease: true
  settings:
    Ensure: Present
    RestartExplorer: true

適用前の OS バージョン検証。

yaml
properties:
  configurationVersion: 0.2.0

  assertions:
    - resource: Microsoft.Windows.Developer/OsVersion
      directives:
        description: Require Windows 11 22H2 or later
        allowPrerelease: true
      settings:
        MinVersion: '10.0.22621'

  resources:
    # Install your tools...

パッケージ適用後に VSComponents を実行する dependsOn

yaml
- resource: Microsoft.WinGet.DSC/WinGetPackage
  id: vsPackage
  directives:
    description: Install Visual Studio 2026 Community
    securityContext: elevated
  settings:
    id: Microsoft.VisualStudio.Community
    source: winget

- resource: Microsoft.VisualStudio.DSC/VSComponents
  dependsOn:
    - vsPackage
  directives:
    description: Install .NET workload
    allowPrerelease: true
    securityContext: elevated
  settings:
    productId: Microsoft.VisualStudio.Product.Community
    channelId: VisualStudio.18.Release
    components:
      - Microsoft.VisualStudio.Workload.ManagedDesktop

#参考文献

編集