How to convert an unmanaged solution into a managed solution in Dynamics 365?

“You see, but you do not observe.” — Arthur Conan Doyle, A Scandal in Bohemia

I had an unusual scenario where an environment was setup with an unmanaged solution and I wanted it to be a managed solution and I needed to convert it. All environments beyond Dev should be managed, so users cannot change customisations. Changes should be made in development and the other environments use the functionality but don’t change it. Stopping changes in environments stops them becoming out of sync, which can affect your testing in those different environments because you are not testing the same customisations.

Converting the solution

I imported the solution with the same publisher in a managed state; I was hoping this would just overwrite the unmanaged solution and customisations and turn them into managed. On import it threw an error and wouldn’t let me convert the unmanaged solution into a managed solution.

Why wouldn’t it let me overwrite it to managed?

I think it’s there to stop developers accidently converted their development environment into a managed environment. This would of a disaster for a development environment because you could no longer change your customisations.

If you did this, the first thing to do when you find yourself in a hole is stop digging. Microsoft backs up your environment hourly for up to 7 days in the past. If you need too you can restore to any hour in the last week. Before you get too excited, remember you would lose customisations and data. It’s very difficult to know what data has been updated and the effort to recreate it is manual, this makes the hourly backup a last option scenario.

Converting the customisations to managed

The internet offered me no help, so I got to thinking (some articles to help you think about your problems)

An unmanaged solution is a container for customisations, if you delete the unmanaged solution, it only deletes the solution. A managed solution is different, if you delete a managed solution, you delete all the data and all the customisations. 

The solutions act differently because unmanaged solutions update the default solution with unmanaged solutions. Managed solutions create another layer of customisations on top of the default solution.

Read more about solution layers

There is a solution layer button is useful to find out how many solutions and different customisations are overlapping on a particular component. This can help diagnose puzzling behaviour and when people have been updating an environment directly.

Conclusion

I deleted the unmanaged solution and then imported the managed solution and this time it worked and turned the unmanaged customisations to managed.