0

For example, I have a .csproj file with the following structure:

...
  <ItemGroup>
    <Compile Include="...">
      <Link>...</Link>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="..." Version="..." />
  </ItemGroup>

  ... there may even be some other tags in between ItemGroups ...

  <ItemGroup>
    <ProjectReference Include="..." />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="...">
      <HintPath>...</HintPath>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <None Update="...">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
  ... There may be even more additional ItemGroups with other content ...
...

Can I merge them all into one, something like this?

...
  <ItemGroup>
    <PackageReference Include="..." Version="..." />
    <ProjectReference Include="..." />
    <Compile Include="...">
      <Link>...</Link>
    </Compile>
    <Reference Include="...">
      <HintPath>...</HintPath>
    </Reference>
    <None Update="...">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
...

I've done it, there seem to be no problem from what I observe at the moment, but I don't want me or other developers to run into them later, not knowing they may be linked to this action.

UяošKoт
  • 416
  • 6
  • 10

1 Answers1

1

Merging them is no problem, it is equivalent from the MSBuild API.

However, some tooling may look for item groups containing only specific things (e.g. NuGet wants to add to item groups that already contain package references), but that means that in the worst case, tools may add additional item groups.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217