Package a code component

This topic describes how to import code components into Common Data Service. After implementing the code components using the PowerApps CLI, the next step is to bundle all the code component elements into a solution file and import the solution file into Common Data Service so that you can see the code components in runtime.

To create and import a solution file:

  1. Create a new folder inside the sample component folder and name it Solution (or any name of your choice) using the command mkdir Solutions. Navigate into the directory using the command cd Solutions.

  2. Create a new solutions project using the command pac solution init --publisher-name <enter your publisher name> --publisher-prefix <enter your publisher prefix>. The solution project is used for bundling the code component into a solution zip file that is used for importing into Common Data Service.


    The publisher-name and publisher-prefix values must be unique to your environment.

  3. Once the new solution project is created, refer the Solution folder to the location where the created sample component is located. You can add the reference using the command shown below. This reference informs the solution project about which code components should be added during the build. You can add references to multiple components in a single solution project.

     pac solution add-reference --path <path to your PowerApps component framework project>
  4. To generate a zip file from the solution project, go into your solution project directory and build the project using the command msbuild /t:build /restore. This command uses MSBuild to build the solution project by pulling down the NuGet dependencies as part of the restore. Use the /restore only for the first time when the solution project is built. For every build after that, you can run the command msbuild.


    • If msbuild 15.9.* is not in the path, open Developer Command Prompt for VS 2017 to run the msbuild commands.
    • Building the solution in the debug configuration generates an unmanaged solution package. A managed solution package is generated by building the solution in release configuration. These settings can be overridden by specifying the SolutionPackageType property in the cdsproj file.
    • You can set the msbuild configuration to Release to issue a production build. Example: msbuild /p:configuration=Release
    • If you encounter an error that says Ambiguous project name when running the msbuild command on your solution, ensure that your solution name and project name are not the same.
  5. The generated solution files are located inside the \bin\debug\ folder after the build is successful.

  6. Manually import the solution into Common Data Service using the web portal or see the Authenticating to your organization and Deployment sections to import using PowerApps CLI commands.

Authenticating to your organization

You can deploy the code components directly from the PowerApps CLI by authenticating to the Common Data Service organization and then pushing the updated components. Use the following steps to create the authentication profile, connect to Common Data Service, and push the updated components.

  1. Create your authentication profile using the following command:

    pac auth create --url <your Common Data Service org’s url> 
  2. If you previously created an authentication profile, you can view all the existing profiles using the following command:

     pac auth list 
  3. To switch between the previously created authentication profiles, use the following command:

     Pac auth select --index <index of the active profile>
  4. To get the basic information about the organization, use the following command. The connection will be made using the default authentication profile.

    pac org who 
  5. To delete a particular authentication profile, use the command pac auth delete --index < index of the profile >.

  6. If you want to clear all the authentication profiles from your local machine, use the command pac auth clear. This action is irreversible because it completely deletes the authprofile.json file and token cache file from your local machine.

Deploying code components

After you have successfully created an authentication profile, you can start pushing the code components to the Common Data Service instance with all the latest changes. The push capability speeds up the inner-developer cycle development because it bypasses the code component versioning requirements and does not require that you build your solution (cdsproj) to import the code component. To use the push capability, do the following:

  1. Ensure that you have a valid authentication profile created.

  2. Navigate to the root directory where the code component project is created.

  3. Run the command pac pcf push --publisher-prefix <your publisher prefix>.


    The publisher prefix that you use with the push command should match the publisher prefix of your solution in which the components will be included.

How to remove components from a solution

If you want to remove a code component from a solution file:

  1. Edit the cdsproj file in the solution project directory and remove the references to the component. Here is an example of a component reference:
    <Projectreference Include="..\pcf_component\pcf_component.pcfproj">
      <Name>pcf_component </Name>
  1. Perform a rebuild (or clean) using the following command:

    msbuild /t:rebuild

See also

Add code components to a field or entity in model-driven apps
Add components to a canvas app
PowerApps component framework API reference
PowerApps component framework overview