Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Visual Studio leave an empty ItemGroup node in the project file?

  • Open Visual Studio and create a new C# project of any type.
  • Add a new folder to the project and save the project.
  • Examine the project file (.csproj) and note that it created a node like this:

    <ItemGroup>
      <Folder Include="NewFolder1\" />
    </ItemGroup>
    
  • Now remove the folder in Visual Studio and save the project.

  • Note that in the project file, there is an empty node, like this:

    <ItemGroup/>
    

Removing the empty node doesn't seem to make any difference, so why does VS leave this behind?

Why do I care? Because commits like this are confusing:

enter image description here

like image 271
Matt Johnson-Pint Avatar asked Mar 11 '15 22:03

Matt Johnson-Pint


1 Answers

Firstly, an empty ItemGroup is benign, just as an empty PropertyGroup is. At worst it's noise in your project file.

Historically, the project file was not really intended for human consumption and only ad-hoc effort was put into keeping it tidy during transformations made by VS.

With the new SDK-style project files, the intent is 100% to have them be human readable and editable. If you see empty groups in VS when using the new project style, it's definitely something the team wants to know about. In such a case, please report a problem and explain in the body that it's for the project system team.

like image 121
Drew Noakes Avatar answered Sep 19 '22 16:09

Drew Noakes