Here it is, what everyone has been waiting for.. an MS build implementation of fizz buzz.
<Project DefaultTargets="CleanupRecur" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Currval Condition="'$(Currval)' == ''">1</Currval> <FileBaseName>$(Targets)</FileBaseName> <FileBaseName Condition="'$(FileBaseName)' == ''">recurfile</FileBaseName> <NextMsbuildFile>$(FileBaseName)-$(Currval).proj</NextMsbuildFile> <NextIndex>$([MSBuild]::Add($(Currval), 1))</NextIndex> <Mod3 Condition="$([MSBuild]::Modulo($(Currval), 3)) == 0">true</Mod3> <Mod5 Condition="$([MSBuild]::Modulo($(Currval), 5)) == 0">true</Mod5> </PropertyGroup> <Target Name="CopyFile"> <Message Text = "$(NextIndex)" /> <Copy Condition="$(Currval) < 100" SourceFiles="$(MSBuildProjectFile)" DestinationFiles="$(NextMsbuildFile)" /> </Target> <Target Name="Fizz" DependsOnTargets="CopyFile"> <Message Condition="'$(Mod3)' == 'true' AND '$(Mod5)' != 'true'" Text="Fizz" Importance="high"/> <Message Condition="'$(Mod5)' == 'true' AND '$(Mod3)' != 'true'" Text="Buzz" Importance="high"/> <Message Condition="'$(Mod3)' == 'true' AND '$(Mod5)' == 'true'" Text="FizzBuzz" Importance="high"/> <Message Condition="'$(Mod3)' != 'true' AND '$(Mod5)' != 'true'" Text="$(Currval)" Importance="high"/> <MSBuild Condition="$(Currval) < 100" Projects="$(NextMsbuildFile)" Targets="CleanupRecur" Properties="Currval=$(NextIndex)"></MSBuild> </Target> <Target Name="CleanupRecur" DependsOnTargets="Fizz"> <Delete Files="$(NextMsbuildFile)" /> </Target> </Project>
You can run it as follows.
# Pass the minimal flag to avoid a bunch of extra msbuild output msbuild /v:minimal .\fizz.proj # The project works by getting the current value of the count from an environment variable "Currval". # It evaluates the mod3 and mod5 of Currval # It then makes a copy of its own project file, to avoid MSBuild detecting any circular dependencies # It than executes MSBuild on the new project file, since it is a dependency, passing the incremented environment variable to the new project # Then it cleans up the newly copied file
There you have it. A working implementation of fizzbuzz using MSBuild.