Skip to content

Add resource hierarchy analyzer tool#57756

Draft
ArcturusZhang wants to merge 5 commits intoAzure:mainfrom
ArcturusZhang:tool/resource-hierarchy-analyzer
Draft

Add resource hierarchy analyzer tool#57756
ArcturusZhang wants to merge 5 commits intoAzure:mainfrom
ArcturusZhang:tool/resource-hierarchy-analyzer

Conversation

@ArcturusZhang
Copy link
Copy Markdown
Member

Adds a reflection-based tool at eng/packages/resource-hierarchy-analyzer/ that analyzes Azure SDK management-plane DLLs and outputs the resource hierarchy as JSON (stdout) and markdown summary (stderr).

What it does

  • Discovers all ArmResource, ArmCollection, and ResourceData subtypes via MetadataLoadContext (reflection-only, no runtime loading)
  • Maps parent-child relationships by inspecting Get*() methods
  • Identifies scopes (ResourceGroup, Subscription) via Mockable extension types
  • Outputs: resource names, data types, tracked/untracked status, collection types, child collections

Usage

dotnet publish sdk/<service>/Azure.ResourceManager.<Service>/src -f net10.0 -o /tmp/publish
dotnet run --project eng/packages/resource-hierarchy-analyzer -- /tmp/publish/Azure.ResourceManager.<Service>.dll

Motivation

Useful for understanding and validating resource hierarchies during mgmt SDK migrations (e.g., Swagger -> TypeSpec).

ArcturusZhang and others added 5 commits April 3, 2026 09:09
Reflection-based tool that analyzes Azure SDK management-plane DLLs
and outputs the resource hierarchy (parent/child relationships, scopes,
data types, collections) as JSON and markdown.

Uses MetadataLoadContext for safe, reflection-only analysis without
loading assemblies into the runtime.

Usage: dotnet run -- <path-to-Azure.ResourceManager.*.dll>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Changed ResourceTypeField from field type name to actual resource type value
  (e.g., 'Microsoft.ContainerInstance/containerGroups')
- Added ResourceId field showing the resource ID pattern from
  CreateResourceIdentifier method parameters
- Uses PEReader IL analysis to extract string literals from static constructors

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Use AssemblyLoadContext to load assemblies and read ResourceType static
  field value directly via FieldInfo.GetValue()
- Get ResourceId pattern by invoking CreateResourceIdentifier with
  placeholder parameter names
- Remove all PEReader/IL bytecode scanning code
- Remove System.Reflection.Metadata/Ecma335 dependencies

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Filter out methods where the return type matches the resource type itself
(e.g., AvailabilitySetResource.Get() returning AvailabilitySetResource).
These are not child resources but self-referencing retrieval methods.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant