Quick Reference – Common Microsoft Power Platform CLI Commands for the Development of PCF Components

To create a PCF component we need to work with multiple Microsoft Power Platform CLI (earlier Power Apps CLI) commands.

This blog lists the common Power Platform CLI commands for quick reference which you may find helpful while working with Power Apps Component Framework.

Following are the high level steps in the development life cycle of PCF control.

  • Installing Power Platform CLI
  • Create a new PCF component project
  • Update node packages
  • Build PCF Project
  • Testing / Debugging PCF component
  • Package PCF code components
    • Create solution project
    • Add PCF component reference in the solution
    • Build the solution zip file
  • Manage authentication profiles
    • Create an authentication profile
    • Listing all authentication profiles
    • Switch between authentication profiles
    • Get information about selected environment
    • Delete an authentication profile from the system
    • Delete all authentication profiles from the system
  • Publishing PCF solution file to Dataverse

Installing Power Platform CLI

Before you can execute any Power Platform CLI command you need to install the Power Platform CLI tooling, which you can get from here.

Reference: Get Tooling for Power Apps component framework.

If you already have installed Power Platform CLI, you can update it to the latest version using the following command

pac install latest

Once PCF tooling is installed you are ready to use Power Apps CLI commands for creating PCF components.

Create a new PCF component project of field or dataset type

For any new PCF control you need to first create a project for it. Use the following commands to create a new PCF component project.

Create a PCF component project template for field component.

pac pcf init --namespace SampleNamespace --name SampleComponent --template field

Create a PCF component project template for dataset component.

pac pcf init --namespace SampleNamespace --name SampleComponent --template dataset

Update node packages

The newly created PCF component project contains the references for node packages in packages.json file but the packages are not installed yet.

Execute following commands in project root folder to install node packages. Note this is node CLI command not Power Apps CLI command.

npm install

Build PCF project

While working with PCF component you will need to build project for multiple reasons such as to re-generate ManifestTypes.d.ts for strong type references of new properties or testing your component.

Type the following to build your project

npm run pcf-scripts build

Or simply

npm run build

Multiple pcf-scripts commands are listed in package.json file while generating new project.

Following are all of the pcf-scripts commands listed in package.json file

"build": "pcf-scripts build"
"clean": "pcf-scripts clean"
"rebuild": "pcf-scripts rebuild"
"start": "pcf-scripts start"

Testing / Debugging PCF Component

When you are ready to test your PCF component you can launch local test harness using the following command. Test harness is handy when you want to test or troubleshoot your code component locally.

npm start

Package PCF code components

When PCF component is ready to be deployed, it needs be packaged into a solution zip file, which then can be imported into Dataverse.

Following are the steps to create a solution zip file from the code component

  • Create a solution project
  • Add reference to the PCF component in the solution
  • Build solution zip file

Create solution project

pac solution init --publisher-name developer --publisher-prefix dev

Add PCF component reference in the solution

pac solution add-reference --path c:\users\SampleComponent

Build the solution zip file

Restore packages

msbuild /t:restore

Build unmanaged solution

msbuild

Build managed release solution

msbuild /p:configuration=Release

Manage authentication profiles

Before you can import solution file using Power Apps CLI, you need to have a authentication profile on your system which points to the target Dataverse environment.

All of the authentication profiles gets saved in the authprofiles.json at following location.

C:\Users\{username}\AppData\Local\Microsoft\PowerAppsCLI\authprofiles.json

This files gets created with the first authentication profile creation and gets deleted with the delete of last authentication profile.

Authentication profiles lets you authenticate and import solutions through the command line. You can use the following commands to manage the authentication profiles on your system.

Create an authentication profile

Use the following command to create a new authentication profile on your system.

pac auth create --url https://{org}.crm.dynamics.com

Listing all authentication profiles

If you need to list all of the authentication profiles available on your system, you can use the following.

pac auth list

Switch between authentication profiles

If you have multiple authentication profiles on your system you may need to switch between profiles. You can switch using the following command.

pac auth select --index <index of the active profile>

Get information about selected environment

If you want to get information about selected authentication profile, use following.

pac org who

Delete an authentication profile from the system

If you want to delete an authentication profile from your system, you can delete using the following command. If this is the last authentication profile on your system then it will also delete authprofiles.json from your system.

pac auth delete --index <index of the profile>

Delete all authentication profiles from the system

If you want to delete all of the authentication profiles from your system, you can delete using the following.

pac auth clear

Publishing PCF solution file to Dataverse

Finally we are ready to publish PCF component solution zip file.

Use following command to publish zipped solution file.

pac pcf push --publisher-prefix dev

Summary

In this blog we went through all the commonly used Microsoft Power Platform CLI commands for the development, testing and publishing of PCF components.

One thought on “Quick Reference – Common Microsoft Power Platform CLI Commands for the Development of PCF Components”

  1. PAC is really useful for managing your PowerApps deployment, however, I’m facing an issue where multiple profiles are active at the same time. Even running the pac auth select marks the one I want, but others keep being active, and when running e.g. an import it uses the first active one it seems.
    Have you experienced this and do you know if it is a bug?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s