One of the ways to quickly backup the plugin/assemblies that are stored in the MSCRM database is to use the Assembly Recovery Tool that comes with XrmToolBox. Recently, I had a situation where I couldn’t back up the assembly this way, as one of the assembly was huge and the OrganizationService was experiencing some latency issues, resulting in a slow performance of the Assembly Recovery Tool.
I followed the method below to quickly backup the assemblies straight from the database.
- Install CShell. I prefer this over Linqpad for quickly running C# snippets because you get intellisense for free and it also has a REPL window.
- Run the query which is below in SQL Server Management Studio, against the MSCRM database
SELECT [Name],[Content] FROM dbo.PluginAssemblyBase WHERE IsHidden=0
- Right click on the result and choose “Save Result As” from the context menu and specify the file name and the location
- Run the code below in the CShell scratchpad
var pluginCsv = System.IO.File.ReadAllLines(@"[FULL PATH OF THE SAVED CSV]"); foreach(var l in pluginCsv) { var content = l.Split(','); var assembly = Convert.FromBase64String(content[1]); System.IO.File.WriteAllBytes(string.Concat(@"[OUTPUT PATH FOR THE ASSEMBLY]",content[0],".dll"),assembly); }
All the assemblies should now be saved to the specified folder. You can use this technique to restore assemblies from database backups of the MSCRM database.
