How dotnet/cli-lab works
Project Type and Purpose
• This project is a command line tool (CLI) for uninstalling .NET Core SDKs, Runtimes, ASP.NET Core Runtimes, and Hosting Bundles.
• Its primary goal is to enable users to remove specific dotnet installations safely and reliably, while managing the complications of being used on different platforms (Windows, macOS, etc.).
Analyzing the File Structure (focusing on dotnet-core-uninstall)
• The dotnet-core-uninstall source is located in the “src/dotnet-core-uninstall” directory.
• Key folders inside include:
– Root files (e.g., Program.cs) which contain the entry point and overall application orchestration.
– A “Shared” directory that contains several submodules:
▪ Commands – Implementations for various uninstall commands (e.g., List, Uninstall, DryRun).
▪ Configs – Command line argument parsing/configuration and option handling.
▪ BundleInfo – Logic to represent and manage information about bundles (the components being uninstalled), including versioning details.
▪ Exceptions – Custom exception types that deal with error conditions like invalid inputs or conflicting versions.
▪ Filterers – Components that filter out bundles depending on options (e.g., filtering out all but the latest version).
▪ Utils – Utility functions (for regex processing, runtime information extraction, etc.).
▪ VSVersioning – Possibly handling Visual Studio version compatibility or extraction.
– Platform-Specific Directories (e.g., “MacOs” and “Windows”) that likely contain code tailored to OS-specific uninstall procedures.
Main Components
a. CLI Entry Point:
• Represented by the main Program.cs which initializes the tool.
• It gathers command line inputs and dispatches them to the appropriate command handlers.
b. Command Dispatcher & Parser:
• Module(s) within “Shared/Configs” that parse input arguments and configuration options.
c. Command Implementations:
• From “Shared/Commands”, illustrate how each command (like UninstallCommand, ListCommand, etc.) is implemented.
• That commands internally call into shared components to perform operations.
d. Bundle Processing Logic:
• The “Shared/BundleInfo” modules encapsulate how bundles are defined, versioned, and managed.
• The “Filterers” interact with BundleInfo to decide which bundles are eligible for uninstallation.
e. Error Handling:
• The “Shared/Exceptions” module where errors (e.g., invalid inputs, version conflicts) are processed.
f. Utility Functions:
• “Shared/Utils” and “Shared/VSVersioning” provide supporting functionality accessible to multiple commands.
g. Platform-Specific Layers:
• Separate modules (under “MacOs” and “Windows”) show the abstraction layer that handles OS-specific operations such as registry queries or file system interactions.
h. Build/Localization:
Relationships and Interactions
• The CLI entry point receives input and passes it to the configuration parser.
• Parsed commands are routed to the appropriate command handler, which then orchestrates:
– Querying the BundleInfo (with data provided by Filterers and Utils).
– Handling errors using custom Exceptions.
– Delegating OS-specific tasks to the platform-specific modules.
• How shared logic (commands, bundle processing, utilities) decouples the core business logic from platform nuances.
Architectural Patterns and Design Principles
• Modular design: Separation of concerns is evident from various “Shared” submodules. It enables easy maintenance and testing.
• Extensibility: The design supports adding new commands or filters without affecting the base structure.
• Platform Abstraction: Encapsulation of OS-specific implementations (in MacOs and Windows subdirectories) allows the tool to operate cross-platform.
• Clear error handling via custom Exceptions, facilitating graceful failures and user feedback.