dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.67k stars 1.06k forks source link

Implement XML Linting for .csproj and Related Files #43583

Open JonDouglas opened 1 week ago

JonDouglas commented 1 week ago

Is your feature request related to a problem? Please describe.

Over the years, I have observed recurring challenges associated with various XML-based project files in the .NET ecosystem, including .csproj, .props, and others. Currently, there is no integrated linter to validate these XML files, which leads to several issues:

Invisible Syntax Errors: Minor mistakes such as missing closing tags (/>) or incorrect nesting can go unnoticed during manual editing. These errors are often not apparent until a build fails, causing frustration and wasting developer time.

Inconsistent Formatting: Without linting, XML files may suffer from inconsistent formatting, making them harder to read and maintain, especially in collaborative environments.

Silent Failures: Some XML errors may not produce clear or immediate feedback, resulting in builds that fail for obscure reasons, complicating the debugging process.

An example of these challenges is documented in NuGet/Home#13469, where the absence of proper linting led to unforeseen issues that could have been prevented with better XML validation.

Describe the solution you'd like

I propose the integration of an XML linting feature within the .NET SDK that specifically targets project-related XML files such as .csproj, .props, and others.

It should validate syntax, enforce basic formatting, report errors, and maybe real time linting in tooling.

richlander commented 1 week ago

+1 ... I had to use a binlog to realize that Directory.Packages.props was not being read, hence why I was seeing 100s of errors. Was very unproductive.

baronfel commented 1 week ago

@rainersigwald @JanKrivanek would this kind of check be doable by a buildcheck?

rainersigwald commented 1 week ago

Not really today, but this is a reasonable extension. We do have https://github.com/dotnet/msbuild/issues/1777 to track other linting.