Repository navigation
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
Open
fix: normalize the paket version of the tool manifest and read the manifest as JSON in #r "paket:"#4502fpellet wants to merge 2 commits into
fpellet wants to merge 2 commits into
Conversation
…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
force-pushed
the
fix/manifest-like-dotnet
branch
from
November 23, 2026 10:20
d30bb51 to
0d96837
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows #4500.
Problem
dotnet tool restorerecords and restores a local tool under its version as NuGet normalizes it:"12.0-alpha003"is restored inpaket/12.0.0-alpha003,"12.0.0+sha"inpaket/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.normalizedNuGetVersionnormalizes a version asNuGetVersion.TryParseandToNormalizedStringof the NuGet of SDK 10 do: one to four Int32 numbers, without the white space ofString.Trimaround the version and each number, prerelease labels without a numeric one with a leading zero, build metadata dropped. ThetoolResolverCacheand the version folder are looked up with it; a version that NuGet refuses is kept as written.Internals.Logic.parseJsonis a small JSON reader:FSharp.DependencyManager.Pakettargets 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.paketOfToolManifestreads the manifest by its structure, as dotnet does: only the tools of"tools"count, the first with the IDpaket, 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
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), andpaketOfToolManifest(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
isRoot, with a tool withoutcommands, or with a version that NuGet refuses, is still read: the lookup goes on above it when it declares no paket and isn'tisRoot, while dotnet stops there with an error. A manifest that isn't JSON declares no paket, and the lookup goes on above it too.