Tuesday, 23 October 2012

MSBuild code formatting

Speaks for itself...

Bad

  <Target Name="MyExampleTarget1">
      <SomeMSBuildTaskThatDoesSomethingOrOtherWithALongName SomePropertyForTheTaskWithALongName="value1" AnotherPropertyForTheTaskWithALongName="value2" />
      <MSBuildTaskWithShortNameName AProperty="value3" />
  </Target>

The end of the line extends outside the editor window so you can't see the end argument without scolling horizontally.

Bad

  <Target Name="MyExampleTarget2">
      <SomeMSBuildTaskThatDoesSomethingOrOtherWithALongName SomePropertyForTheTaskWithALongName="value1" 
                                                            AnotherPropertyForTheTaskWithALongName="value2" />
      <MSBuildTaskWithShortName SomeProperty="value3" />
  </Target>
 
The properties don't line up ("SomeProperty" not aligned with the properties from the previous task) making it a bit harder to read.

Good

  <Target Name="MyExampleTarget3">
      <SomeMSBuildTaskThatDoesSomethingOrOtherWithALongName 
          SomePropertyForTheTaskWithALongName="value1"
          AnotherPropertyForTheTaskWithALongName="value2" />
      <MSBuildTaskWithShortName 
          SomeProperty="value3" />
  </Target>
 
Everything almost always fits in the editor window (no need to scroll horizontally) and everything lines up making it easy on the eye.

About Me