Skip to content

dotnet tool manifest updates strip trailing newlines and BOM #53045

@Thomas-Shephard

Description

@Thomas-Shephard

dotnet tool commands (install, update, uninstall) perform an invasive rewrite of the dotnet-tools.json manifest that disregards original file formatting and encoding.

Issues

  1. Trailing Newline Stripping: Commands always strip the trailing newline. This causes "dirty diffs" in automated updates (Dependabot/Renovate) and breaks linting/EditorConfig rules requiring a final newline.
  2. BOM Removal: Files saved as UTF-8 with BOM are rewritten as UTF-8 without BOM.
  3. UTF-16 Crash: The CLI crashes with Json parsing error: '0xFF' is an invalid start of a value when reading UTF-16 LE manifests because ToolManifestEditor.cs uses JsonDocument.Parse on a raw stream.

Technical Detail

The implementation in src/Cli/dotnet/ToolManifest/ToolManifestEditor.cs uses a strict "Read into Model -> Write from Model" pattern without capturing file metadata.

  • DeserializeLocalToolsManifest uses JsonDocument.Parse(jsonStream) which lacks encoding detection.
  • ToJson uses Utf8JsonWriter which does not append a final newline.
  • File.WriteAllText is called without preserving the original encoding.

Expected Behavior

The SDK should detect and preserve the existing file's encoding and trailing whitespace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions