
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:
- Delegated permission
- 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
- An Azure AD app.
- Understanding of solution concepts.
- Understanding of environments.
- An environment to which a solution needs to be imported.
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.

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.


Thanks for reading 🙂
One thought on “Importing Power Platform solution – 2”