Skip to content

Empty newlines between groups in .csproj files to be kept to have same behavior as C# code #1599

@johan-lindqvist

Description

@johan-lindqvist

It's nice to see that XML-files are now formatted. This is a borderline opinion request but since it works this way in C# code I would expect the same for XML code.

If there is one newline between ItemGroup and PropertyGroups they should be kept, if multiple then they should be reduced to one.

Input:

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<OutputType>Exe</OutputType>
		<TargetFramework>net8.0</TargetFramework>
	</PropertyGroup>
	
	<ItemGroup>
		<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
	</ItemGroup>

	<ItemGroup>
		<ProjectReference Include="..\OtherProject.csproj" />
	</ItemGroup>

	<ItemGroup>
		<None Update="appSettings.json">
			<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
		</None>
	</ItemGroup>
</Project>

Output:

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<OutputType>Exe</OutputType>
		<TargetFramework>net8.0</TargetFramework>
	</PropertyGroup>
	<ItemGroup>
		<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
	</ItemGroup>
	<ItemGroup>
		<ProjectReference Include="..\OtherProject.csproj" />
	</ItemGroup>
	<ItemGroup>
		<None Update="appSettings.json">
			<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
		</None>
	</ItemGroup>
</Project>

Expected behavior:
For the empty newlines to be kept if there is only one between groups. Expected result:

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<OutputType>Exe</OutputType>
		<TargetFramework>net8.0</TargetFramework>
	</PropertyGroup>
	
	<ItemGroup>
		<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
	</ItemGroup>

	<ItemGroup>
		<ProjectReference Include="..\OtherProject.csproj" />
	</ItemGroup>

	<ItemGroup>
		<None Update="appSettings.json">
			<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
		</None>
	</ItemGroup>
</Project>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions