Skip to main content
rule official · GitHub

pcf-code-components — GitHub Copilot rule: PCF component structure

A rule that teaches Copilot how Power Apps code components are built: manifest, TypeScript implementation, resources. Useful when editing ControlManifest.Input.xml or index.ts.

Install into GitHub Copilot · Manually: put the files in place All methods and platforms ↓
.github/instructions/pcf-code-components.instructions.md
Open on GitHub

What pcf-code-components does

The rule applies to files matching **/*.{ts,tsx,js,json,xml,pcfproj,csproj} and lays out the three parts of a code component: manifest, implementation, resources. The manifest is ControlManifest.Input.xml. It names the component, declares whether it works with a field or a dataset, lists configurable properties, and points at the resource files the component needs. Those properties show up as configuration columns in the app, and the platform uses the manifest to filter which components are valid in a given context.

Implementation is TypeScript. Every component object must provide init, updateView and destroy; getOutputs is optional and fires when the user changes data. You do not write the stubs by hand — pac pcf init from Power Platform CLI generates an index.ts with them. On page load the platform builds an object from the manifest data and calls init(context, notifyOutputChanged, state, container).

Resources live under the resources node, and at least one code resource is required. CSS files, image web resources and .resx files for localization can be added on top. Skip destroy and event handlers may keep consuming memory after the user leaves the page, so it pays to check that method before shipping. setControlState stores data for the next load within the same session.

What it helps with

  • figure out which fields ControlManifest.Input.xml requires
  • trace the order of init, updateView and getOutputs calls
  • scaffold a component with pac pcf init
  • wire CSS and .resx files into a component
  • plug a memory leak by implementing destroy

Example prompts for the agent

  • Which properties do I need to declare in ControlManifest.Input.xml for a field component?
  • Walk me through the lifecycle: why did updateView fire but not getOutputs?
  • Add a CSS resource and a .resx file for localization to the manifest.

How to install pcf-code-components

Manually: put the files in place

.github/instructions/pcf-code-components.instructions.md

The applyTo field sets which files it applies to

Step by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use

Questions about pcf-code-components

How do I install pcf-code-components in GitHub Copilot?

Copy the rule file to .github/instructions/pcf-code-components.instructions.md in your repository. Copilot picks it up for files matching the applyTo glob.

What does pcf-code-components do?

It tells Copilot how code components in Power Apps component framework are structured: manifest, TypeScript implementation, resources. Suggestions around ControlManifest.Input.xml and index.ts then follow the framework's actual rules.

Do model-driven and canvas apps need different components?

The definition and implementation via Power Apps component framework are the same for both. Only the configuration part differs.

Source text

pcf-code-components.instructions.md · MIT
---
description: 'Understanding code components structure and implementation'
applyTo: '**/*.{ts,tsx,js,json,xml,pcfproj,csproj}'
---

# Code Components

Code components are a type of solution component that can be included in a solution file and imported into different environments. They can be added to both model-driven and canvas apps.

## Three Core Elements

Code components consist of three elements:

1. **Manifest**
2. **Component implementation**
3. **Resources**

> **Note**: The definition and implementation of code components using Power Apps component framework is the same for both model-driven and canvas apps. The only difference is the configuration part.

## Manifest

The manifest is the `ControlManifest.Input.xml` metadata file that defines a component. It is an XML document that describes:

- The name of the component
- The kind of data that can be configured, either a `field` or a `dataset`
- Any properties that can be configured in the application when the component is added
- A list of resource files that the component needs

### Manifest Purpose

When a user configures a code component, the data in the manifest file filters the available components so that only valid components for the context are available for configuration. The properties defined in the manifest file are rendered as configuration columns so that users can specify values. These property values are then available to the component at runtime.

More information: [Manifest schema reference](https://learn.microsoft.com/en-us/power-apps/developer/component-framework/manifest-schema-reference/)

## Component Implementation

Code components are implemented using TypeScript. Each code component must include an object that implements the methods described in the code component interface. The [Power Platform CLI](https://learn.microsoft.com/en-us/power-platform/developer/cli/introduction) auto-generates an `index.ts` file with stubbed implementations using the `pac pcf init` command.

### Required Methods

The component object implements these lifecycle methods:

- **init** (Required) - Called when the page loads
- **updateView** (Required) - Called when app data changes
- **getOutputs** (Optional) - Returns values when user changes data
- **destroy** (Required) - Called when the page closes

### Component Lifecycle

#### Page Load

When the page loads, the application creates an object using data from the manifest:

```typescript
var obj = new <"namespace on manifest">.<"constructor on manifest">();
```

Example:
```typescript
var controlObj = new SampleNameSpace.LinearInputComponent();
```

The page then initializes the component:

```typescript
controlObj.init(context, notifyOutputChanged, state, container);
```

**Init Parameters:**

| Parameter | Description |
|-----------|-------------|
| `context` | Contains all information about how the component is configured and all parameters. Access input properties via `context.parameters.<property name from manifest>`. Includes Power Apps component framework APIs. |
| `notifyOutputChanged` | Alerts the framework whenever the component has new outputs ready to be retrieved asynchronously. |
| `state` | Contains component data from the previous page load if explicitly stored using `setControlState` method. |
| `container` | An HTML div element to which developers can append HTML elements for the UI. |

#### User Changes Data

When a user interacts with your component to change data, call the `notifyOutputChanged` method passed in the `init` method. The platform responds by calling the `getOutputs` method, which returns values with the changes made by the user. For a `field` component, this would typically be the new value.

#### App Changes Data

If the platform changes the data, it calls the `updateView` method of the component and passes the new context object as a parameter. This method should be implemented to update the values displayed in the component.

#### Page Close

When a user navigates away from the page, the code component loses scope and all memory allocated for objects is cleared. However, some methods (like event handlers) may stay and consume memory based on browser implementation.

**Best Practices:**
- Implement the `setControlState` method to store information for the next time within the same session
- Implement the `destroy` method to remove cleanup code such as event handlers when the page closes

## Resources

The resource node in the manifest file refers to the resources that the component requires to implement its visualization. Each code component must have a resource file to construct its visualization. The `index.ts` file generated by the tooling is a `code` resource. There must be at least 1 code resource.

### Additional Resources

You can define additional resource files in the manifest:

- CSS files
- Image web resources
- Resx web resources for localization

More information: [resources element](https://learn.microsoft.com/en-us/power-apps/developer/component-framework/manifest-schema-reference/resources)

## Related Resources

- [Create and build a code component](https://learn.microsoft.com/en-us/power-apps/developer/component-framework/create-custom-controls-using-pcf)
- [Learn how to package and distribute extensions using solutions](https://learn.microsoft.com/en-us/power-platform/alm/solution-concepts-alm)

© github · MIT · github/awesome-copilot

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set732

The whole set →

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor