Why your Power Platform Setup Needs a Repo
Tags: powerplatform, powerapps, powerautomate, lowcode
Published: 2024-07-15 06:18:04

A Repo (repository) is simply a place to store what you develop. Github is probably the most famous repository (though it does more then just that), but there are others like BitBucket, Artificatory and Assembla.

It can be stored as code (editable individual files) or packages (aka artifacts), there are multiple benefits but the main are:

- Source control (different save versions)
- Redudenancy (back up)
- Multi dev working (split/merge different versions)
- Integrated Deployments (Dev/Test/Prod)


So the question you are now asking is why would I need a repo in the Power Platform, my Apps and even flows now, have version history. Each environment has a copy of the solution, and I store copies when I manually deploy or through Pipeline (A copy of the solution is stored in Dataverse). But there are a few reasons, and it is also easier then you think, so lets dive in.

1. Why - whats the benefits
2. How to setup

---

## 1. Why - whats the benefits
**Connections**
There is one big big problem in the Power Platform, that also happens to be its biggest strength, connections. Conenctions are great, you use your own so no messing around setting up spn's ([Service Principle Name](https://learn.microsoft.com/en-us/entra/identity-platform/app-objects-and-service-principals?tabs=browser)), but now we have a problem, they are your connections. Which means we really shouldnt be sharing ([hacked by power automate and how to avoid it](https://dev.to/wyattdave/hacked-by-power-automate-and-how-to-avoid-it-3052)), this is fine in Default on your personal solutions, but what about when its a business solution. If you want other devs to be able to update/maintain the flows/apps you have to give them access to your connections, which not only causes security issues but can cause export issues (if a flow uses a different persons connection reference, you can't see it in the solution so will export without it, causeing dependency issues).

And this is where a repo comes in, once development is finished it is uploaded to the repo and deleted from the environment. Next dev who needs to work on it simply downloads and imports with their connections.

![repo process](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kajofhk946zbnlojk72x.png)

**Code Consistency**
I have seen far to often a solution deployed to prod, the develeoper then 'tinkers' with the dev version trying new things out. They stop and forget, when a new update is required these unlogged changes cause unexpected behaviour and bugs. Or the flip side there is a bug in prod and you can't recreate it in dev as you are actually working on a different version.

Again going to the repo ensures you are always working off the right version.

**House Keeping**
Dev environments can get very very messy very quickly. It can become hard top navigate and monitor on. Not to forget that it is all stored in Dataverse, which we have limited capacity (and it is not cheap to buy more). One solution is to burn the environment (delete after x days), and this is a good solution, but means you really need a repo even more else solutiosn could be lost.

Storing in a repo keeps your dev environment tidy and will most likely save you money in the long run.

**Back ups**
Although Power Platform environments do have recorvery back ups it is good practice to diversify your storage. Storing on different platforms ensures you do not lose your data if any accidents/disaters happen. It also helps from personal errors (A dev deletes a solution by mistake, a environment rollback would then wipe any other developers work since back up).
 
![backups](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0cv2x2mxvqh9i199hvps.png)

---

## 2. How to setup
There are 2 main ways to store your solution, as code or as an artifact.

If you want to go the code route then for Power Apps you would need to use the Git version control (its been in experimental for 2 years+ now) that integrates directly with Github, I wont go into this as there is good documentation [here](https://learn.microsoft.com/en-us/power-apps/maker/canvas-apps/git-version-control).

For Power Automate you have more options as at its core it is row in a Dataverse table ([workflows](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/reference/entities/workflow)), so you can store it in any database. You would also need to do the same for Connection Referenes, Environment Variables and other components. All do-able (Ive gone into detail whats in a solution [here](https://dev.to/wyattdave/everything-you-didnt-know-you-needed-to-know-about-power-platform-solutions-1b4)), but I would strongly recommend going with the easier artifact approach.

In this approach we let the Power Platform do all the packing and we just download the completed zip file with everything we need.

As we are just storing a zip file it can be anywhere, so the easy one is obviously SharePoint, but if you want to do it properly I would still recommend somewhere like Artifactory.

The Dataverse api has the [ExportSolution Action](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/reference/exportsolution?view=dataverse-latest) which creates the solution export. You pass in some key information and it returns the zip file. So its easy to integrate with pro code solutions, but the easier way is to leverage Power Automate and the Dataverse Unbound Action (which calls the same api).

The below example exports the solution and creates an item in a SharePoint list. It stores some key information and a unique reference (run Guid). It then attaches the export to the item.

![export flow](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xo7btkuq4i9mug3texmw.png)

This can be called when needed (like when dev finishes for the he day), on a schedule, or during the deployment process.

![trigger options](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eqc13c29er56zpudb1k2.png)

---

Repos can be thought of another 'burden' to maintain, with a 'its low code so I dont need pro code processes approach' or 'Its all do before me by Microsoft', but what we should really be looking at is the value. If the solution has high value, then we need to be risk adverse, and this is when established pro code processes like ALM (Application Lifecycle Management) and repos come in (why re-invet the wheel).