AgentSkillsCN

pcf-controls

当您使用React、Vue或TypeScript在VS Code中构建、搭建、调试或部署Microsoft Power Apps组件框架(PCF)控件时使用此功能。支持通过pac CLI进行项目初始化,通过@microsoft/power-apps SDK访问Dataverse与连接器数据,使用power.config.json配置文件,采用Vite构建管道,并部署至Power Platform环境。可通过“Power Apps”“代码应用”“PAC代码”“Dataverse”“Power Platform应用”“Vibe编码”“搭建Power App”“部署代码应用”等语句触发。

SKILL.md
--- frontmatter
name: pcf-controls
description: >
  Use when building, deploying, or using PowerApps Component Framework (PCF) controls.
  Covers field controls and dataset controls, React virtual controls, control lifecycle,
  manifest configuration, solution packaging, and deployment. Triggers on: "pcf",
  "custom control", "component framework", "dataset control", "virtual control",
  "pac pcf", "pcf init", "pcf push", "ControlManifest", "StandardControl",
  "ReactControl", "updateView", "getOutputs".
license: MIT
compatibility: "Power Apps Component Framework, Dataverse"
metadata:
  author: custom
  version: "1.0.0"
  platform: "Microsoft Power Platform / Dataverse"

PCF Controls Skill

You are an expert at building PowerApps Component Framework (PCF) controls for Microsoft Power Platform. You know the full PCF development lifecycle — from scaffolding with pac pcf init, through TypeScript implementation, test harness debugging, solution packaging, and deployment to Dataverse environments. You build both field controls (bound to a single column) and dataset controls (bound to views/subgrids), and you leverage React virtual controls for complex UIs that need the full React component model with Fluent UI integration.

CRITICAL RULES

  1. Use pac pcf init to scaffold — never create from scratch. The CLI generates the correct project structure, tsconfig, manifest, and build pipeline. Hand-creating these files leads to subtle build errors and missing type definitions.

  2. TypeScript is required (not plain JS). PCF controls must be authored in TypeScript. The framework's type system (ComponentFramework.StandardControl<IInputs, IOutputs>) provides compile-time safety for the context object, parameters, and outputs. Never use plain JavaScript.

  3. React virtual controls for complex UIs (--framework react). When your control needs rich interactivity (lists, drag-drop, modals, complex state), use virtual controls. These return React elements from updateView() instead of manipulating the DOM directly. The platform hosts the React tree — do not install or bundle your own React. Use --framework react during pac pcf init.

  4. Field controls vs Dataset controls — know the difference.

    • Field controls bind to a single column value. Use --template field. The control reads/writes one value via context.parameters.<propertyName> and notifies the host via notifyOutputChanged() + getOutputs().
    • Dataset controls bind to a view or subgrid. Use --template dataset. The control receives a full record set via context.parameters.dataSet with sorting, filtering, and paging APIs. Dataset controls render collections of records (grids, calendars, kanban boards, galleries).
  5. Always test in harness first (npm start watch). The test harness provides a sandboxed environment with mock data, parameter configuration, and hot reload. Never deploy untested controls to an environment. The harness catches most manifest misconfigurations and runtime errors before they reach production.

  6. Solution packaging required for production deployment. While pac pcf push is convenient for development (pushes directly to a dev environment), production deployment requires proper solution packaging: pac solution initpac solution add-referencemsbuild /t:build /restorepac solution import. This produces a managed or unmanaged solution .zip that can be transported across environments.

  7. Never modify auto-generated files (generated/*.ts). The ManifestTypes.d.ts and other files under generated/ are regenerated on every build from the manifest XML. Any manual edits will be overwritten. If you need to change types, update ControlManifest.Input.xml and rebuild.

  8. Use context.webAPI for Dataverse operations within controls. For CRUD operations inside a control, use the provided context.webAPI.createRecord(), retrieveMultipleRecords(), updateRecord(), deleteRecord(). Do not import or use the Xrm global object — it is not guaranteed to be available and is not part of the supported PCF API surface.

Quick Reference — PAC PCF Commands

CommandPurpose
pac pcf init --namespace NS --name Name --template fieldScaffold a standard field control
pac pcf init --namespace NS --name Name --template datasetScaffold a standard dataset control
pac pcf init --namespace NS --name Name --template field --framework reactScaffold a React virtual field control
pac pcf init --namespace NS --name Name --template dataset --framework reactScaffold a React virtual dataset control
npm installInstall dependencies after scaffolding
npm run buildBuild the control (compiles TS, bundles output)
npm start watchLaunch test harness with hot reload
pac pcf push --publisher-prefix picPush control to connected dev environment
pac solution init --publisher-name PIC --publisher-prefix picInitialize a solution project for packaging
pac solution add-reference --path ../MyControlAdd a PCF control project to the solution
msbuild /t:build /restoreBuild the solution .zip
pac solution import --path bin/Debug/Solution.zipImport solution to connected environment
pac pcf version --strategy manifestBump version based on manifest

Decision Guide — PCF vs OOB vs Web Resources

ScenarioRecommendationRationale
Need a slider, toggle, or rating input on a formPCF field controlBound to column, participates in form save, type-safe
Need a custom grid/calendar/kanban for a viewPCF dataset controlGets full dataset API with sort/filter/paging
Need a dashboard with charts and custom HTMLWeb resourceNot column-bound, standalone HTML page
Need to change field visibility/requirement on form eventsForm script (web resource JS)PCF controls cannot modify other form fields
Need a button on the command barCommand bar customization / RibbonPCF controls live inside field or subgrid areas, not command bar
Need complex interactive UI (drag-drop, modals, trees)PCF React virtual controlFull React component model, Fluent UI, platform-managed React
Simple formatting change (bold, color, icon)OOB column formatting (Power FX)No code deployment needed, column formatting rules suffice
Need to override the entire form experienceCustom page / Code AppPCF controls are per-field or per-subgrid, not full-page
Need offline support in mobile appPCF field control (with caveats)PCF supports offline if control does not depend on webAPI calls
Need to call external APIs from UIPCF control with context.webAPI or fetchControls can make HTTP calls; use environment variables for URLs

Resource Files

FileContents
resources/pcf-lifecycle.mdControl lifecycle (initupdateViewgetOutputsdestroy), StandardControl and ReactControl interfaces, context object deep dive, dataset APIs, scaffolding and debugging
resources/component-patterns.md11 common PCF control patterns (slider, toggle, rating, color picker, rich text, map, kanban, calendar, gallery, chart, file upload) with implementation guidance and manifest config
resources/manifest-reference.mdComplete ControlManifest.Input.xml schema reference, property types, data-set elements, resources, feature-usage, solution packaging workflow, and full XML examples