RicoSuter / DNT

DNT (DotNetTools): Command line tools to manage .NET projects and solutions.
MIT License
416 stars 63 forks source link

Restore original project file line endings after Microsoft.Build has overwritten them #105

Closed kimsey0 closed 3 years ago

kimsey0 commented 3 years ago

Fixes #98.

@RicoSuter: I don't know if this is too invasive?

It first reads the full project file into memory and looks for a single CRLF to determine the line endings. This could be changed to use a reader and only read until the first newline. Alternatively, the logic could be changed to count and compare number of carriage returns and newlines (for example checking if CR > LF / 2) to better handle mixed line endings.

Then it reads the whole file into memory again at the end to replace the line breaks, if they differ from the line endings used by Microsoft.Build. I don't think this can be done in a streaming fashion without using a temporary file, but that may be preferable.

I haven't been able to find a way to override the behavior of Microsoft.Build.Evaluation.Project.Save.

RicoSuter commented 3 years ago

Seems fine to me... thanks for the PR.