Working with managed solutions in production environments bring multiple advantages (see previous post on managed vs. unmanaged solutions), however, one of the disadvantages is that once you deploy a managed solution, you are no longer able to delete some of its components. A typical example is that you deploy a solution with a custom entity and you figure out that you must change the data type of an attribute. CRM in general will not allow you to change the data type of an attribute, you will need to delete the attribute and re-create it with the new type (even if you use unmanaged solutions); however if your managed solution is already deployed you cannot delete the attribute, so what do you do? I will offer 3 different alternatives I have used in the past:
1. Hide instead of delete. The easiest solution is to simply create the new attribute with the correct data type and completely hide the old attribute from all views, forms, reports, etc. In many cases, deleting an attribute in production is unacceptable because of data loss so this alternative is the safest and most conservative as you get to keep the old data. The disadvantage is that you will have useless columns in your database and the old attribute will continue to appear in Advanced Find.
2. Use a holding solution to delete any component from your deployed managed solution. This is my favourite approach as it has the advantage of completely deleting from the system the unwanted components without losing any data. This is how it works: Assume you have a solution XXX which contains a custom entity and one of the attributes is of type “Single Line of Text” but you want to change it to “Multiple Lines of Text”. In your target environment you should have solution XXX as managed and in your development environment you should have solution XXX as unmanaged.
- In your development environment create a new solution “XXX_holding”. The publisher must be the same as the publisher of your XXX solution.
- Add all the components of the XXX solution to your XXX_holding solution*.
- Export XXX_holding as managed.
- Import XXX_holding to your target environment.
- Delete XXX solution from your target environment. No data is lost because all the customizations remain in the holding solution.
- In your development environment delete the attribute (you will need to adjust views, forms, etc.).
- Export XXX as managed.
- Import XXX to your target environment
- Delete XXX_holding from your target environment. The attribute will now be deleted from all environments. There is no data loss except for the data that was saved in the old attribute which was deleted.
- Now that the attribute is deleted, if you want the attribute back but with a different data type you just need to re-create it in dev and promote the solution to your target environment.
3. Uninstall and re-install solution. If you absolutely need to wipe out the old attribute from the system, you could also uninstall the entire managed solution, make the appropriate changes in your development environment and then re-deploy a clean and correct version of your managed solution. The big disadvantage here is that you will lose your data if it relies on the customizations of your solution, which is usually unacceptable unless you have no data to retain or the data is not important.
4. Use unmanaged solutions instead of managed solutions. While it is true that with unmanaged solutions it is simpler to manually delete any component, it is also true that deploying unmanaged solutions to a production environment has multiple disadvantages and is not a good practice in my perspective. It might also be too late for you to switch to unmanaged solutions. You can read more on best practices around managed vs. unmanaged solutions here. There’s also an interesting white paper from Microsoft for building ISV solutions.
Some posts in the MSDN forums additionally suggest that Microsoft is aware of this limitation and might consider a better solution in the future. For the time being I have found the holding solution approach to work well, please let me know if you have other experiences or suggestions!
I came to same second option for deleting web resources, fields.
ReplyDeleteBut before step 3, I delete field of entity in development environment and only then export solution XXX_holding.
Otherwise, you will not be able to import solution XXX in step 8, as you cannot change type of existing field when importing solution.
Makes sense, thanks!
ReplyDelete"...deploying MANAGED solutions to a production environment has multiple disadvantages and is not a good practice in my perspective."
ReplyDeleteJust making sure I understand, did you mean "...deploying UNMANAGED solutions to a production environment has multiple disadvantages and is not a good practice in my perspective"?
Juan, you're absolutely right, it was a typo. I have corrected it, thanks for reporting it!
ReplyDeleteGonzalo, do you have a time/risk estimate for option # 2 for an environment with medium-high amount of customizations?
ReplyDeleteI would say the risk is low (provided you have a roll-back mechanism in place) and it should not take you longer than 1 day + testing. You can try first in a dev environment to verify.
ReplyDeleteI did option 2 on CRM Online. However, now when I update the primary solution it fails with the error: 0x80040217, solution With Id = XXX-GUID-XXX Does Not Exist.
ReplyDeleteIt fails on an entiy which had a relationship with the deleted entity so I wonder if there is still something in there. I have looked but can't see anything out of place.
Ever seen this happen and have an idea of what to check?
This does not work anymore since rollup 6.
ReplyDeleteSome data will be still in the database when removing the managed solution (like attributemap values and also form labels) These cause major errors when your system now is running rollup 11. Microsoft then advises to re-install and import all data again.
Gonz, do you have any response or verification on the Anyonymous comment from January 18, 2013 about rollup 6?
ReplyDeleteNice blog. keep it up....
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteIs the holding solution approach unsupported by MS?
ReplyDeleteGrey area. Definitely not recommended in production environment. However, you should be able to delete managed components in future version of CRM
DeleteYes, it is. Microsoft uses the holding solution approach when you deploy your solutions via the Package Deployer.
DeleteActually Microsoft acknowledges it but does not specifically endorse it. In CRM 2016 they added the necessary SDK messages and UI to support this scenario and is now supported hen you use the solution upgrade "staging" process.
DeleteHi, I have an issue in that a relationship isn't in my unmanaged dev environment but when I import it as a managed solution into UAT it's there. And as it's managed I can't delete it. Where is this relationship coming from and any idea how do I delete?! Thanks
ReplyDeleteHi Gonz,
ReplyDeleteIs there a way to change the attribute state from managed to unmanaged from unmanaged solution
this is not possible
Delete