Skip to content

fix: normalize the paket version of the tool manifest and read the manifest as JSON in #r "paket:" - #4502

Open
fpellet wants to merge 2 commits into
masterfrom
fix/manifest-like-dotnet
Open

fpellet wants to merge 2 commits into
masterfrom
fix/manifest-like-dotnet

Conversation

@fpellet

@fpellet fpellet commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Follows #4500.

Problem

  • dotnet tool restore records and restores a local tool under its version as NuGet normalizes it: "12.0-alpha003" is restored in paket/12.0.0-alpha003, "12.0.0+sha" in paket/12.0.0. #r "paket:" looked for the tool under the version as the manifest writes it, and took it as not restored.
  • #r "paket:" read the tool manifest with regular expressions: it looked for a "paket" object and for "isRoot" anywhere in the manifest, and for the version of paket before the first }, without case. An "IsRoot", a property in a comment, or the "paket" object of another tool when it had a version counted, and an object in the paket tool hid the properties after it.

Change

  • Internals.Logic.normalizedNuGetVersion normalizes a version as NuGetVersion.TryParse and ToNormalizedString of the NuGet of SDK 10 do: one to four Int32 numbers, without the white space of String.Trim around the version and each number, prerelease labels without a numeric one with a leading zero, build metadata dropped. The toolResolverCache and the version folder are looked up with it; a version that NuGet refuses is kept as written.
  • Internals.Logic.parseJson is a small JSON reader: FSharp.DependencyManager.Paket targets netstandard2.0 with FSharp.Core only, and runs in F# Interactive, also on .NET Framework, where System.Text.Json isn't there. It is lenient: it skips comments and trailing commas, which dotnet refuses, and doesn't check the form of the numbers or the control characters in strings. It reads 64 levels of objects and arrays at most, so that a manifest can't overflow the stack.
  • paketOfToolManifest reads the manifest by its structure, as dotnet does: only the tools of "tools" count, the first with the ID paket, in any case, and a version; "version", "rollForward" and "isRoot" are read with their case, the last of each when it is written twice. It doesn't validate the rest of the manifest. A manifest that isn't JSON, which dotnet refuses too, now declares no paket, where the regular expressions could still find one in it.

The zsh completion is unchanged.

Docs: a release note for each change.

Commits

  1. the version as NuGet normalizes it, with its tests and its release note;
  2. the manifest read as JSON, with its tests and its release note.

Tests

tests/Paket.Tests/FsiExtension.fs: the normalization (forms that NuGet normalizes or refuses), parseJson (values and escapes, depth of arrays and objects, escapes that aren't JSON), and paketOfToolManifest (a "paket" object in another tool or out of "tools", an object in the paket tool, "isRoot" and "rollForward" in a comment, trailing commas, "IsRoot", "Version" and "Tools" with another case, the tool ID "Paket", two IDs that differ only by case, a property written twice, a manifest that isn't a JSON object).

Limits

  • A manifest that dotnet refuses, such as one without isRoot, with a tool without commands, or with a version that NuGet refuses, is still read: the lookup goes on above it when it declares no paket and isn't isRoot, while dotnet stops there with an error. A manifest that isn't JSON declares no paket, and the lookup goes on above it too.
  • The zsh completion and the MSBuild targets still look for paket in the text of the manifest.

@fpellet fpellet changed the title fix: read the tool manifest as dotnet does in #r "paket:" and the zsh completion fix: normalize the manifest version and read the manifest as JSON in #r "paket:" Nov 23, 2026
@fpellet fpellet changed the title fix: normalize the manifest version and read the manifest as JSON in #r "paket:" fix: normalize the paket version of the tool manifest and read the manifest as JSON in #r "paket:" Nov 23, 2026
…he manifest in #r "paket:"

dotnet tool restore records and restores the tool under its version as the
NuGet of the SDK normalizes it: 12.0-alpha003 is restored in
paket/12.0.0-alpha003, and 12.0.0+sha in paket/12.0.0. NuGet also removes
the white space of String.Trim around the version and around each of its
numbers: "12. 0.0" is 12.0.0, and a no-break space before the "-" of a
prerelease is dropped. The local tool was looked for under the version as
the manifest writes it, so it was taken as not restored.
The regular expressions of #r "paket:" looked for a "paket" object and for
"isRoot" anywhere in the manifest, and for the version of paket before the
first "}", without case: an "IsRoot", a property in a comment, or the
"paket" object of another tool when it had a version counted, and an object
in the paket tool hid what follows it.

As the extension targets netstandard2.0, without System.Text.Json, a small
JSON reader now reads the manifest by its structure, as dotnet does: only
the tools of "tools" count, the first with the ID paket, in any case, and a
version, and "version", "rollForward" and "isRoot" are read with their case,
the last of each when it is written twice. It is lenient: it skips comments
and trailing commas, which dotnet refuses. A manifest that isn't JSON, which
dotnet refuses too, now declares no paket, where the regular expressions
could still find one in it. The reader goes 64 levels deep at most, so that
a manifest can't overflow the stack.
@fpellet
fpellet force-pushed the fix/manifest-like-dotnet branch from d30bb51 to 0d96837 Compare November 23, 2026 10:20

This branch has not been deployed

No deployments
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