Back
Featured image of post Generating Solution Settings File via the Microsoft Power Platform CLI

Generating Solution Settings File via the Microsoft Power Platform CLI

I’ve been doing some serious playing around with the Microsoft Power Platform CLI recently. It’s come a long way. Previously, this tool was primarily used as our main companion when building out Power Apps Component Framework (PCF) controls. Today, the CLI has been enhanced in several key areas, increasing its flexibility and establishing itself as a less cumbersome option than the traditional SDK tools that longstanding Dynamics CRM / Dynamics 365 developers may be accustomed to working with. This week in the blog, I wanted to dive into a specific area of this tooling that we can use to support our Application Lifecycle Management (ALM) processes involving Microsoft Dataverse - namely, solution settings files.

What is a Solution Settings File?

For anyone familiar with importing solutions manually, we’ll recall that we’re typically asked to specify Environment Variable values and Connection Reference details whenever we import a solution:

Specifying these settings is crucial, as they will dictate how our various apps and automations operate. Therefore, it’s natural that we would want a mechanism to specify these in all deployment scenarios, particularly ones that involve Azure DevOps and the Power Platform Build Tools. Previously, we could not set these, meaning that our solution deployments potentially ended up within an undesirable state, requiring manual intervention and, in some cases, the creation of unintentional unmanaged layers on our various solution components. With a settings file, we can now non-interactively specify the settings outlined in the screenshot above. To better understand how settings files work, let’s dive into an end-to-end scenario, where we demonstrate how to generate and leverage them.

Export Solution

The first step before kicking things off is to export a suitable solution from our environment. For this example, we are working with a solution that contains a couple of Environment Variables and Connection References:

We can either export the solution manually from the maker portal or do this via a CLI command instead. First, let’s set up an authentication profile and ensure we set it as our default:

pac auth create -n CLIDemo -u https://mydataverseorg.crm4.dynamics.com/
pac auth select -n CLIDemo

You will be prompted to log in via an interactive prompt. Once complete, we’ll be able to run the following command to export our solution as managed:

pac solution export -p C:\MySolutionFolder -n MySolution -m true

Generate the File

With a solution file to work with, we can now proceed to generate the settings file via the following command

pac solution create-settings -z C:\MySolutionFolder\MySolution.zip -s C:\MySolutionFolder\MySettings.json

What’s nice about this command is that we can also run against the expanded contents of our solution. Let’s assume we’ve done that via the following command:

pac solution unpack -z C:\MySolutionFolder\MySolution.zip -f C:\MySolutionFolder\MySolution\ -p Managed

We can then make some slight changes to our create-settings command, as indicated below:

pac solution create-settings -f C:\MySolutionFolder\MySolution\ -s C:\Users\joejg\Downloads\MySettings.json

Regardless of which route we go down, the result will be a file similar to this:

Evaluating the File

The file is a simple JSON document which, based on the example components below, would resemble the following:

{
  "EnvironmentVariables": [
    {
      "SchemaName": "jjg_DecimalEV",
      "Value": ""
    },
    {
      "SchemaName": "jjg_TextEV",
      "Value": ""
    },
    {
      "SchemaName": "jjg_YesNoEV",
      "Value": ""
    }
  ],
  "ConnectionReferences": [
    {
      "LogicalName": "jjg_AzureBlobStorage",
      "ConnectionId": "",
      "ConnectorId": "/providers/Microsoft.PowerApps/apis/shared_azureblob"
    },
    {
      "LogicalName": "jjg_Dataverse",
      "ConnectionId": "",
      "ConnectorId": "/providers/Microsoft.PowerApps/apis/shared_commondataserviceforapps"
    }
  ]
}

The critical elements of the file include:

  • A list of all the Environment Variables found in the solution
  • All of the Connection References contained in the solution, with details for the relevant API’s they relate to

The file is designed to be edited and allows us to specify what we desire the current values of our Environment Variables need to be…

    {
      "SchemaName": "jjg_DecimalEV",
      "Value": 12.5
    },
    {
      "SchemaName": "jjg_TextEV",
      "Value": "Sample Text"
    },
    {
      "SchemaName": "jjg_YesNoEV",
      "Value": true
    }

…and likewise, for our Connection References. The steps here are a little bit more involved, though. It’s expected the relevant Connections for our Connection References already exist in the target environment. So, in this case, let’s assume I have the following two connections set up for Dataverse and Azure Blob Storage:

We need to navigate into each of these and then extract out the URL, which will resemble the following:

https://make.powerapps.com/environments/752c0a39-e2eb-4140-9ce3-31a65228b3b2/connections/shared_azureblob/a0b52ba3bd6b420c92bd4826e4601658/details#

The piece of information we’re interested in is contained in the penultimate portion of the URL, between /shared_azureblob and /details#, which we can then add onto the ConnectionId property accordingly:

{
    "LogicalName": "jjg_AzureBlobStorage",
    "ConnectionId": "a0b52ba3bd6b420c92bd4826e4601658",
    "ConnectorId": "/providers/Microsoft.PowerApps/apis/shared_azureblob"
}

Using the Settings File During a Deployment

As we’ve discussed already, the settings file’s main purpose is to help in automation scenarios. This means we can leverage it when importing a solution via the CLI:

pac solution import -p C:\MySolutionFolder\MySolution.zip -s C:\MySolutionFolder\MySettings.json

However, the most typical usage scenario will be from an Azure DevOps perspective. As part of the Import Solution task, we’ll see we’ve got an option to indicate we plan to use our settings file, with a link to where it’s located in our build artefact:

After our import is complete, we can observe that our Environment Variables have the desired current values and that our Connection References are linked to our desired connection.

Conclusion or Wot I Think

Settings files undoubtedly provide a crucial piece of the puzzle when implementing healthy and automated ALM involving the Power Platform. I have a gripe that there is still no (easy) way to programmatically create the underlying connections that we can then use as part of our Connection References. Granted, many connection types will always require some form of interactive authentication. Still, this gap does mean we have to do a degree of preparation against our targeted environments to ensure our automation works as expected. And, when it comes to weighing up between using Power Automate cloud flows or Azure Logic Apps, this gap does weigh towards us considering the latter option, as this is typically not a problem we face. Nevertheless, I would encourage organisations to leverage settings files as part of their automated DevOps deployments to begin working smarter, not harder. 😉

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy