Rohan Nevrikar

Cloud Consultant @ Rapid Circle

Importing Power Platform solution – 2

Kedarkantha base camp
Sunset at Kedarkantha base camp (December 2019)

This post is the second part of a two-part blog series on Importing Power Platform solution.

In this series, I would like to show how a Power Platform solution can be programmatically imported into a target environment using two ways:

  1. Delegated permission
  2. Application user

Introduction

In the first part of this blog series, I wrote about how can we import a Power Platform solution from a user’s context using delegated permission of Dynamics CRM. But what if we want to import a solution from an application’s context, where there is no user interaction at all? In this blog, I’ll try to explain the same.

Prerequisites

Application User

As the name suggests, an Application User is something which acts as a user in behalf of an application. It maps an AAD application to a Dynamics CRM user. This user can then be assigned roles just like any other user.

To create an application user, go to Advanced Setting of your environment. Click on Settings drop-down, click on Security -> Users, and then choose Application Users from the drop-down. Create new application user. Add username, full name and email for your new user. For Application ID, enter the client ID of your AAD app.

Create application user

Click on Save. Now that we have an app user for our application, we need to assign that user required roles. Click on Manage roles and assign System Administrator role. This will enable the app user to import solutions in an environment.

Code

We’ll be using XRM Tooling SDK to manage solutions using C#. Install Microsoft.CrmSdk.XrmTooling.CoreAssembly Nuget package.

Our next step would be to form connection string for CRM. There are many connection methods available, but we need to form connection string for ClientSecret, as we want to use client credentials for connecting to CRM.

string connectionString = $"AuthType = ClientSecret;url = {orgUrl};ClientId = {ClientId};ClientSecret = {ClientSecret}"; //form the connection string. Notice that AuthType is ClientSecret for client credentials

Once we have the connection string ready, we’ll use that to connect to CRM and get service client.

CrmServiceClient serviceClient = new CrmServiceClient(connectionString);

We’ll use this service client to import desired solution to the target environment.

byte[] fileBytes=File.ReadAllBytes(solutionFilePath);

ImportSolutionRequest impSolReq = new ImportSolutionRequest()
{
    OverwriteUnmanagedCustomizations = true,
    CustomizationFile = fileBytes
};

serviceClient.Execute(impSolReq); //imports solution

Demo

I have created a simple console app which uses client credentials to connect to CRM and import solution in the target environment.

C# console app which imports a solution to an environment
The solution which got imported in the target environment

Thanks for reading 🙂

Links

Published by

One response to “Importing Power Platform solution – 2”

  1. […] Post Previous post: Meeting Scheduler Bot in Teams: Bot FrameworkNext Post Next post: Importing Power Platform solution Rohan Nevrikar, Blog at WordPress.com. Create your website at WordPress.comGet […]

    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

Blog at WordPress.com.

%d bloggers like this: