Removing unmanaged solutions via API
Views (578)
After some time, you will have multiple solutions in your CRM environment. In my case, there were multiple unmanaged solutions, as I have transferred many customizations between my test- and productive environment.
Via the solution menu in the settings, you can delete unused solutions, but only one after each other. This consumes much time and therefore I wrote a tool to delete unmanaged solutions, which were modified more than 1 month ago.
XmlConfigurator.Configure();
_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
using (var orgService = new CrmServiceClient(Connection)) // creating the client
{
var query = new QueryExpression // creating the query
{
EntityName = "solution", // entity is solution
ColumnSet = new ColumnSet("uniquename"),
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("ismanaged", ConditionOperator.Equal,
false), // only getting unmanaged solutions
new ConditionExpression("isvisible", ConditionOperator.Equal,
true), // only get visible solutions
new ConditionExpression("uniquename", ConditionOperator.NotEqual,
"Default"), // exclude the default solution, which is also marked as unmanaged
new ConditionExpression("modifiedon", ConditionOperator.LessThan,
DateTime.Now.AddMonths(-1)) // getting all solution, modified more than 1 month ago
}
}
};
var result = new ConcurrentBag<Entity>(orgService.RetrieveMultiple(query).Entities); // getting the result and add it to a threadsafe list
Parallel.ForEach(
result,
new ParallelOptions {MaxDegreeOfParallelism = 4}, // using maximum parallelism of 4, as crm usually only allows 4 connections per ip
solution =>
{
_log.Info($"Deleting solution {solution.GetAttributeValue<string>("uniquename")}"); // writing the solutionname to the log
orgService.Delete(solution.LogicalName, solution.Id); // deleting the solution
}
);
}
Comments
-
Removing unmanaged solutions via APIThank you for sharing this. I needed a quick way to get rid of hundreds of solutions with some options to customize the delete so I really appreciate this code! Works as expected.

Like
Report
*This post is locked for comments