dotnet tool manifest updates strip trailing newlines and BOM
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
`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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.