Sorted order of files in .csproj

Viewed 3627

In a Visual Studio csproj, the files to compile are referenced like this:

<ItemGroup>
    <Compile Include="C\Something.cs"> 
    <Compile Include="B\SomethingElse.cs"> 
    <Compile Include="A\YetSomethingElse.cs"> 
</ItemGroup>

It seems to me that the order is random (at least I cannot see an ordering principle).

It happened a few times that during fixing of merge conflicts, I mistakenly added a file twice (since there are a lot of files, and the file on the line of the merge conflict was at another position in the list already). This would be easy to avoid if there was a way to just sort the Compile Included files alphabetically.

Is this possible already (or do I have to write a script myself)? Are there any side effects I would have to be aware of?

2 Answers

SortProjectItems is a command-line utility I just discovered that might help mitigate this problem. It's not a permanent fix: Visual Studio will continually screw up the sort order of items within the .csproj file over time. But it's as close to a solution as I've found thus far, and it's a lot better than nothing.

Related