Skip to content

Terminate generated packages.lock.json with a newline #15168

Backlog

Description

@konard

dotnet restore with .NET SDK 11.0.100 writes a multiline packages.lock.json without a final newline. This causes the end-of-file-fixer Git hook to modify newly generated lockfiles. The resulting file restores correctly in locked mode, but a developer or bot regenerating the lock gets a recurring whitespace change.

Minimal reproduction in an empty scratch directory:

dotnet new classlib --no-restore
dotnet restore --use-lock-file --force-evaluate
python3 -c 'from pathlib import Path; print(repr(Path("packages.lock.json").read_bytes()[-5:]))'

Actual output: b' }\n}'. Expected: the same formatted JSON with a final \n after the closing brace. Our current workaround is to run the hook to add the newline and stage the resulting lockfile, as in link-foundation/csharp-ai-driven-development-pipeline-template#127.

Could PackagesLockFileFormat.Write in NuGet.ProjectModel append a literal LF after its JSON writer flushes, with a test that verifies byte-stable output across platforms and parses it back in locked mode? That would let us regenerate and stage the lockfile in one step. The extra byte is valid JSON whitespace.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions