msbuild
msbuild copied to clipboard
Fix the addxml when add node after comment xml node
trafficstars
Fixes #11933
Context
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /><!-- some comment -->
</ItemGroup>
dotnet add package Serilog --version 4.3.0 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>
Changes Made
If the reference element is immediately followed by a series of XML nodes, each of which does not contain any line breaks and is whitespace, a comment, or a processing instruction, then insert the new element after those nodes.
Testing
AddPackageReference_PreservesTrailingCommentOnSameLine