Skip to content

Write enum defaults from packages by name - #111

Merged
Mpdreamz merged 1 commit into
mainfrom
nuget-enums
Nov 15, 2026
Merged

Mpdreamz merged 1 commit into
mainfrom
nuget-enums

Conversation

@Mpdreamz

Copy link
Copy Markdown
Contributor

An optional parameter's enum default is stored as a number; writing it by name needs the assembly that declares the enum. A library's bin/Release holds only the library, not its packages, so an enum from a package came out as a cast:

string Export(object value, Formatting formatting = (Formatting)1)    // before
string Export(object value, Formatting formatting = Formatting.Indented)    // after
  • Projects: for each library and framework, api asks MSBuild for ProjectAssetsFile and reads obj/project.assets.json. It takes the package assemblies that framework compiles against, under the packages folders the file names, and passes their directories to the reader. Nothing new to configure.
  • A .dll, a directory or a .nupkg: there is no project to read, so -r/--reference <dir> (repeatable) names the folders to look in. A missing folder is an error. --verify's suggested update command carries the flag.
  • An enum that happens to be in the ASP.NET shared framework, such as LogLevel, used to resolve only on machines with that runtime installed. Through the project's restore it now resolves everywhere.

Verified:

  • New ApiReferenceTests build a project against a package on a local feed, with Mode.Auto as a default:
    • api in the project writes Mode.Auto;
    • the bare DLL writes (Mode)5 without -r and Mode.Auto with it;
    • a missing -r folder is an error.
  • Mutations caught: leaving out the package directories, and ignoring the reference directories.
  • Checked by hand on a library using Newtonsoft.Json and Microsoft.Extensions.Logging.
  • mise run ci is green locally.

🤖 Generated with Claude Code

A library's build output holds only the library, so an enum from a package, `Formatting formatting =
Formatting.Indented`, was written as a cast, `(Formatting)1`. The api command now reads each project's
obj/project.assets.json and gives the reader the directories of the package assemblies the framework compiles
against. A .dll, directory or .nupkg read on its own takes them with -r/--reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Mpdreamz Mpdreamz added the feature A new capability (minor bump) label Nov 15, 2026
@Mpdreamz
Mpdreamz merged commit 8adb442 into main Nov 15, 2026
8 checks passed
@Mpdreamz
Mpdreamz deleted the nuget-enums branch November 15, 2026 08:28
Mpdreamz added a commit that referenced this pull request Nov 15, 2026
…#112)

Follow-up to #111. A `.nupkg` read on its own (`assembly-differ api
MyLib.1.2.0.nupkg`) wrote an enum default from a dependency as a cast
unless `-r` named the folder. It now finds its dependencies itself:

- It reads the package's dependency group for each framework (the
nearest one, as restore picks it), and does the same for each dependency
in turn, transitively.
- It looks for each one in the packages folder restore fills:
`~/.nuget/packages`, `NUGET_PACKAGES`, or what NuGet.config says.
- It takes the version restore would: the lowest the range allows, among
versions whose restore finished (`.nupkg.metadata` present).
- It reads the dependency's `ref/` assemblies when it has them,
otherwise `lib/`, for the nearest framework.
- **Nothing is downloaded:** a dependency that is not in the folder is
skipped, and its enums stay casts, as before. `-r` still adds folders on
top.

**Verified:**
- `A_package_finds_its_dependencies_in_the_packages_folder` packs a real
project whose package declares the enum:
  - with the restored packages folder it writes `Mode.Auto`;
  - with an empty one it writes `(Mode)5`, with no error.
-
`A_package_takes_the_version_restore_would_through_its_dependencies_dependencies`
uses a hand-made packages folder:
  - `Uses` depends on `Middle`, which depends on `Modes [1.1.0, )`;
- `Modes` is there at 1.0.0, at 1.1.0 with an unfinished restore, at
1.2.0 and at 2.0.0, and each declares value 5 under a different name;
  - so the name written tells which version was read, and it is 1.2.0.
- Mutations caught: taking the highest version, taking an unfinished
restore, not following dependencies' dependencies, and not passing the
folders to the reader.
- Checked by hand on a packed library that depends on Newtonsoft.Json.
- `mise run ci` is green locally.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature A new capability (minor bump)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant