web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

How to Automatically Detect & Remove Unwanted Solution Components in Dynamics365

Inogic Profile Picture Inogic 1,055 Super User 2025 Season 2

Imagine yourself managing a sprawling Dynamics 365 solution, bloated with thousands of components, including web resources, entities, and plugins, many of which are unused web resources with no dependencies. Cleaning them up via the Power Apps maker portal (https://make.powerapps.com/) means scrolling through endless lists and manually deleting each one, a tedious and error-prone task. One wrong move could break dependencies, crashing your solution. This common headache for Dynamics 365/Dataverse developers and admins boils down to two challenges:

  • Manually reviewing and deleting thousands of components through the UI is time-consuming and error-prone.
  • Identifying unreferenced components to avoid breaking dependencies (e.g., linked to forms or processes) is risky and disruptive.

Here comes our tech-saviors, the powerful duo of RemoveSolutionComponentRequest and RetrieveDependenciesForDeleteRequest from Microsoft.Crm.Sdk.Messages, your cleanup superheroes.

These SDK classes work together to programmatically target and remove unreferenced components from an unmanaged solution, with dependency checks to ensure safety. In this blog, you’ll learn how to streamline solution cleanup with key code snippets, components, and benefits for efficient maintenance.

Approach

The aim is to replace manual UI deletions with an automated script that identifies solution components in SampleSolution (e.g., web resources with no dependencies) and removes them safely.

The process uses a QueryExpression to target web resources (ComponentType=61) and checks dependencies to ensure only idle components are deleted.

The steps include:

  • Connecting to Dataverse using CrmServiceClient.
  • Querying solutioncomponent and linked webresource entities to find components.
  • Validating dependencies with RetrieveDependenciesForDeleteRequest.
  • Removing unreferenced components with RemoveSolutionComponentRequest.
  • Logging actions and pausing the console for debugging.

This approach eliminates manual effort, ensures safety, and scales for large solutions.

Step-by-Step Guide

This guide provides a practical walkthrough to set up a console script that cleans up unreferenced web resources in Dynamics 365/Dataverse. We’ll focus on web resources with no dependencies, ensuring only those with no dependencies are removed. Set up an Azure AD app registration for authentication (ClientId, ClientSecret, org URL)...Read More

Comments