How nulastudio/netbeauty2 works
Main Components
• Core NetBeauty Engine - Represented by the “NetBeauty” directory with submodules:
– src/main: Contains the primary beautification logic (beauty.go, bindata.go)
– src/manager: Coordinates the beautification process (manager.go)
– src/log: Handles logging (log.go)
– src/nbloader: Contains the custom loader code to support runtime modifications
– src/misc and src/util: Utility functions and OS-specific behaviors (umask/hide & util code)
• Build & Configuration:
– The “Build” directory holds PowerShell scripts for building, signing, and pushing NuGet packages.
– The “Common” folder holds shared MSBuild properties.
• Package & Integration:
– NetBeautyNuget and NetBeautyGlobalTool projects provide integration (as a NuGet package and as a global tool respectively) that customers incorporate into their own projects.
• Test Suites:
– The “NetBeautyTest” folder contains several test projects (AvaloniaTest, ChromelyTest, NetFxTest, RazorTest, SharedRuntimeTest, etc.) that simulate different deployment scenarios and UI frameworks. These help demonstrate how the beautification is applied in various contexts.
• Documentation & Design Support:
– The “docs” folder includes design documents that further explain concepts like anti-debugging, how nbloader works, and recommended application structures.
– The README itself shows examples of before/after folder structures and usage patterns.
• Additional Supporting Components:
– The “nbloader” folder contains an alternative implementation (in C#) of the loader hook which might interact directly with runtime initialization.
Relationships and Data Flow
• The primary data flow begins with a .NET application’s published directory, which is then handed over to the NetBeauty engine (either through a post-build/publish hook or via the separate binary/global tool).
• The engine (using its main module) employs the manager to coordinate how files are moved (with logging support) and may invoke the NBLoader for patching or loading runtime libraries.
• When used as a NuGet package, the source project’s build scripts and MSBuild properties (from the Common folder and custom configurations in the csproj) invoke the beautification tasks.
• Test projects simulate how different types of .NET applications (GUI through Avalonia/WPF/Razor, cross-platform via Chromely) integrate with the beautification process.
• The output is a reorganized runtime directory structure, which can optionally include a shared runtime model (as shown in the “Shared Runtime Structure” section in the README).
Architectural Patterns and Design Principles
• Modularity: The project is segmented into distinct modules (main logic, loader, utilities, logging, and manager) that work together.
• Extensibility: It supports multiple frameworks (.NET Framework, .NET Core) and deployments (FDD, SCD, FDE) via runtime configuration.
• Integration Orientation: In addition to a core engine, it provides integration points (via NuGet and as a global tool) so that external projects can adopt it seamlessly.
• Separation of Concerns: The build scripts, the core business logic of beautification, and the testing suite are clearly separated in different directories.
• Configurability: The csproj file examples show how properties such as shared runtime mode, patch options, log levels, and file exclusions are managed through MSBuild properties.
Relevant Technologies
• .NET (Core and Framework) – with integration into build and publish phases.
• PowerShell – for scripting build and deployment tasks.
• MSBuild – driven by the Common.props and project configurations.
• NuGet – for dependency management and packaging.
• C# and Go – with parts of the project implemented in each language (e.g., the main NetBeauty project uses Go, while some global tool and test projects use C#).