Skip to content

add package command doesn't properly retain XML comments #14329

@brettfo

Description

@brettfo

NuGet Product Used

dotnet.exe

Product Version

.NET SDK 9.0.204

Worked before?

No

Impact

It bothers me. A fix would be nice

Repro Steps & Context

Create a .csproj with the following contents:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /><!-- some comment -->
  </ItemGroup>
</Project>

Run the following command:

dotnet add package Serilog --version 4.3.0

Result:

The trailing comment on the Newtonsoft.Json line is moved to the newly added package.

<ItemGroup>
  <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
  <PackageReference Include="Serilog" Version="4.3.0" /><!-- some comment -->
</ItemGroup>

Expected:

The trailing comment on the Newtonsoft.Json line should have stayed put.

<ItemGroup>
  <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /><!-- some comment -->
  <PackageReference Include="Serilog" Version="4.3.0" />
</ItemGroup>

Verbose Logs

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