Skip to content

Project editing does not preserve comment placement #1503

Open
@cdmihai

Description

@cdmihai

Input (whitespace in the itemgroup is garbled on purpose):

<!-- comment -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  
  <!-- comment -->
  <ItemGroup>

    <i Include="a">
         <!-- comment -->
           <m>metadata value</m>
    </i>

  </ItemGroup>

</Project>

Action:

projectRootElement.AddProperty("P", "v");

Actual Output. The comment above the itemgroup is separated from the itemgroup, and no trailing whitespace is added after the propertygroup:

<!-- comment -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  
  <!-- comment -->
  <PropertyGroup>
    <P>v</P>
  </PropertyGroup>
  <ItemGroup>

    <i Include="a">
         <!-- comment -->
           <m>metadata value</m>
    </i>

  </ItemGroup>

</Project>

Desired Output:

<!-- comment -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  
  <PropertyGroup>
    <P>v</P>
  </PropertyGroup>

  <!-- comment -->
  <ItemGroup>

    <i Include="a">
         <!-- comment -->
           <m>metadata value</m>
    </i>

  </ItemGroup>

</Project>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions