How to convert Managed Solution into Unmanaged for On-Premise CRM organisation?

Solution is very important part of Dynamics CRM. In order to deploy your customization, solution is the only bridge which help you to achieve your goal. There are two types of solutions available in CRM: Managed and Unmanaged.

Managed Solutions:

This is the solutions that you can import and publish only. You neither export it nor you can make any changes in it.

Unmanaged Solutions:

It allows you to perform all operations like Import, Export, add/remove component, publish customization and lot other.

In this blog we are mainly focusing on restriction of Managed solution and how to convert Managed solution into Unmanaged one. Once you convert Managed solution into Unmanaged, then you can do anything with it.

Description & Solution:

When you install any third party solution, mostly you will find them in Managed state.

The reason behind this is, anonymous person cannot modify the component of Managed solution. In other words, it is in lock state.

Suppose you come across the situation in which you need to export the Managed solution to deploy it on Production environment then you won’t be able to do that. Same way you cannot update any component within the solution.

After doing lot of research work I came up with below solution which help me to convert solution from managed state to unmanaged one.

This solution will only applicable on “on premise” version of Dynamics CRM.

I will also suggest to take the backup of you CRM Database first.

Below is the SQL query which you have to use in order to convert Managed solution into Unmanaged one.

DECLARE @solutionId UNIQUEIDENTIFIER  
 DECLARE @systemSolutionId UNIQUEIDENTIFIER  
 -- Please replace 'UNIQUE NAME OF YOUR MANAGED SOLUTION' with the name of your solution name.  
 SELECT   
   @solutionId = solutionid  
 FROM SolutionBase  
 WHERE   
   UniqueName='UNIQUE NAME OF YOUR MANAGED SOLUTION'  
 -- DO NOT TOUCH FROM HERE ON --  
 SELECT   
   @systemSolutionId = solutionid   
 FROM SolutionBase   
 WHERE UniqueName = 'Active'  
 UPDATE PublisherBase SET   
   IsReadonly=0  
 WHERE PublisherId IN (SELECT PublisherId FROM SolutionBase WHERE SolutionId = @solutionId)  
 PRINT 'Updated Publisher'  
 DECLARE @tables TABLE (   
   id     INT IDENTITY,   
   NAME    NVARCHAR(100),   
   ismanaged BIT,   
   issolution BIT   
 )  
 DECLARE   
   @count    INT,   
   @currentTable NVARCHAR(100),   
   @currentM   BIT,   
   @currentS   BIT,   
   @sql     NVARCHAR(max)   
 -- Go through all the tables that have the ismanaged or solutionid flag  
 -- Find the related records for the current solution and move them to the crm active solution.  
 INSERT INTO @tables (  
   NAME, ismanaged, issolution  
 )   
 SELECT   
   NAME, 1, 0   
 FROM  sysobjects   
 WHERE  
   id IN (SELECT id FROM syscolumns WHERE NAME IN ( 'IsManaged' ))   
   AND type = 'U'   
 ORDER BY NAME   
 INSERT INTO @tables (  
   NAME, ismanaged, issolution  
 )   
 SELECT  
   NAME, 0, 1   
 FROM  sysobjects   
 WHERE  
   id IN (SELECT id FROM syscolumns WHERE NAME IN ( 'SolutionId' ))   
     AND type = 'U'   
     AND NAME NOT IN ( 'SolutionComponentBase' )  
 ORDER BY NAME   
 -- Ignore this table because it doesn't make a difference.   
 -- It does cause dependency errors on the exported solution but we can manually edit the xml for that.  
 SELECT @count = Count(*)   
 FROM  @tables   
 WHILE ( @count > 0 )   
  BEGIN   
    SELECT @currentTable = NAME,   
        @currentM = ismanaged,   
        @currentS = issolution   
    FROM  @tables   
    WHERE id = @count   
    IF ( @currentM = 1 )   
     BEGIN   
       SELECT @sql = 'update ' + @currentTable   
              + ' set IsManaged=0 where SolutionId=N'''   
              + Cast(@solutionId AS NVARCHAR(100)) + ''''   
       EXEC (@sql)   
       PRINT 'updated IsManaged to 0 on: '   
          + @currentTable   
     END   
    IF ( @currentS = 1 )   
     BEGIN   
       SELECT @sql = 'update ' + @currentTable   
              + ' set SolutionId=N'''   
              + Cast(@systemSolutionId AS NVARCHAR(100))   
              + ''' where SolutionId=N'''   
              + Cast(@solutionId AS NVARCHAR(100)) + ''''   
       EXEC (@sql)   
       PRINT 'updated SolutionId on: ' + @currentTable   
     END   
    SELECT @count = @count - 1,   
        @currentTable = NULL   
  END   

Follow below steps once you done with above SQL Script.

Download the managed solution which you want to convert and search for MissingDependency tag in solution.xml file.

There will be many MissingDependency elements exists in solution.xml file. Please remove all of them and close the MissingDependency missing tag as <MissingDependency />

Now zip all files into single and again import in your organization.

That’s it..!!!

Conclusion:
Some time you come across the situation with Managed solution in Microsoft CRM development and there is no way to overcome the situation unless you have some way to manage the changes. This blog will help you to resolve all your problems related to Managed solution.

jameswarner

James Warner is a highly skilled and experienced software and mobile application system development manager at NexSoftsys. He has wide experience in IT industries to develop a creative business system based on dynamics 365 for finance and operations partners, Asp.net development, Big data services.

3 comments:

  1. Hi James,
    I think you are missing a note on your article, that this approach is *NOT* Supported by Microsoft

    Regards
    Joao

  2. Hi James,

    Thank you for this tutorial.

    Not that the solution is unmanaged, how can I remove it from the system? I tried to delete it, but it still detects a bunch on dependencies. I even removed all the components, so now it’s pretty much empty, but it still detect the same dependencies.

    So, I exported it, removed all dependencies from the Solution.xml file, and reimported. Still, no luck,

    Appreciate any advice!

  3. Thanks, James.
    It works fine. My SQL deployment doesn’t like > in the query … I had to change in >. Everything else was ok.

Leave a Reply

Your email address will not be published. Required fields are marked *