0
votes

I use a build file to build and test my project. I have a Compile-Target which has this line "Targets = "Rebuild". Do I really need this line? Using Visual Studio I know that I can clean a Solution and build it again, or I can just rebuild the solution. In my msbuild-file I delete my main folder BuildArtifacts before creating him again. I used this Tutorial and I don't know why he uses Target=Rebuild? This is my build file:

<Project ToolsVersion="4.0" DefaultTargets="RunUnitTests" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 

  <!-- Falls Eigenschaften nicht gesetzt -> Release & Any CPU als default-->
  <PropertyGroup>
    <!-- ... -->
  </PropertyGroup>

  <ItemGroup>
    <!-- ... -->
  </ItemGroup>

  <!-- All the stuff go into my main folder -->
  <Target Name="Init" DependsOnTargets="Clean">
    <MakeDir Directories="@(BuildArtifacts)" />
  </Target>

  <!-- delete my main folder -->
  <Target Name="Clean">
    <RemoveDir Directories="@(BuildArtifactsDir)" />
  </Target>

  <!-- delete NUnit-Files -->
  <Target Name="CleanAfter">
    <RemoveDir Directories="@(NunitDir)" />
  </Target>

  <Target Name="Compile" DependsOnTargets="Init">
    <MSBuild Projects="@(SolutionFile)" 
    Targets="Rebuild" 
    Properties="OutDir=%(BuildArtifactsDir.FullPath);
    Configuration=$(Configuration);
    Platform=$(BuildPlatform)" />
  </Target>

  <Target Name="RunUnitTests" DependsOnTargets="Compile">
         <Exec Command='"@(NUnitConsole)" "@(UnitTestsDLL)" --result=console-test.xml --work=BuildArtifacts' />
         <CallTarget Targets="CleanAfter" />
  </Target>

</Project>
1

1 Answers

1
votes

This depends on your own needs: do you need the whole solution to be rebuilt or not? Arguably, on a build server, you want to do a complete clean/rebuild after every commit to make sure the codebase is sane. Removing just the output directory (I assume that is what the Clean starget does) doesn't necessarily remove all object files as well since they typically go into the intermediate directory which might not be the same as the output directory.