Enforce style check for unreferenced public code in dotnetup
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
## Context
From [PR #53464 review discussion](https://github.com/dotnet/sdk/pull/53464#discussion_r3048196733):
**@dsplaisted** flagged that several constants in `Constants.cs` (`Symbols` and `Ansi` nested classes) are declared `public` but not referenced anywhere in the codebase.
**@nagilson** noted this isn't easily caught by current analyzers:
> "This isn't really supported due to how the analyzers are written. We could make the code in dotnetup internal perhaps instead of public in many cases so IDE0051 catches it. In theory maybe we could also use NDepend or something."
## Problem
AI sometimes declares public constants and APIs that are never referenced. Since the project is an executable (not a library consumed by others), unreferenced `public` members are dead code but go undetected because:
- **IDE0051** (Remove unused private members) only flags `private` members.
- **IDE0052** (Remove unread private members) similarly scopes to `private`.
- No built-in Roslyn analyzer catches unreferenced `public`/`internal` members in non-library projects.
## Proposed Solutions
1. **Change default visibility to `internal`**: Since `dotnetup` is an executable, not a public API surface, most types and members should be `internal`. This would let IDE0051 catch unused members. Only keep `public` where required (e.g., entry point, serialization contracts).
2. **Audit existing `public` declarations**: Do a sweep of `src/Installer/dotnetup/` to downgrade unnecessary `public` to `internal`.
3. **Evaluate tooling for dead-code detection**: Consider NDepend, or a custom Roslyn analyzer / `.editorconfig` rule that warns on unreferenced `internal` members in executable projects.
## Files of Interest
- `src/Installer/dotnetup/Constants.cs` — `Symbols` and `Ansi` classes were the original examples
- Broadly applies to all `public` types/members in the `dotnetup` project
## Related
- PR: https://github.com/dotnet/sdk/pull/53464
- Discussion: https://github.com/dotnet/sdk/pull/53464#discussion_r3039852842
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.