In order to use the MSBuild tasks for DuplicateFinder, you will need the libraries DuplicateFinderLib.dll and DuplicateFinder.Tasks.dll.
The simple way to use them is to place them in your $(MSBuildExtensionsPath), which is typically C:\Program Files\MSBuild

Then you can use it in MSBuild scripts, as in this simple example:

<Project DefaultTargets="RunTest"
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    
  <UsingTask TaskName="DuplicateFinder" 
	AssemblyFile="$(MSBuildExtensionsPath)\DuplicateFinder.Tasks.dll" />

  <ItemGroup>
    <TestFiles Include="..\..\TestData\*.txt"/>
  </ItemGroup>

  <Target Name="RunTest">
    <DuplicateFinder Files="@(TestFiles)" />
  </Target>
</Project>


Parameters to the DuplicateFinder task are as follows:

Files: The files to inspect. Required. Note that the ExcludedFiles option is not present, since an MSBuild file group can both include and exclude files.

DuplicateThreshold: As per the commandline arguments.

FocusFile: As per the command line arguments.

FirstLineMinWidth: As per the command line arguments.

ExcludedLinePrefixes: as per the commandline arguments. Multiple prefixes can be specified on multiple lines inside the quotes as per the example below. These lines are trimmed for leading and trailing white space so indentation is unimportant.

CountThresholdForError: The task will fail if this number or more duplicates are found.

LengthThresholdForError: The task will fail if this length or longer duplicates are found.

CountThresholdForError and LengthThresholdForError work together. e.g. if CountThresholdForError =3 and LengthThresholdForError = 10, the task will fail on three or more duplicates of length 10 lines or more, but will not fail on two duplicates of length 12, or on 4 duplicates of length 9.

CountThresholdForError2 and LengthThresholdForError2 are optional, and set a second threshold for error. Likewise CountThresholdForError3 and LengthThresholdForError3.

e.g.
		CountThresholdForError="10"
		LengthThresholdForError="6"
		CountThresholdForError2="1"
		LengthThresholdForError2="16"


This will fail the build on 10 more more duplicates of length 6 or more, or on any duplicates of length 16 or more.


Here is a more complex example, which uses all the optional parameters:
<Project DefaultTargets="RunTest"
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    
  <UsingTask TaskName="DuplicateFinder" 
	AssemblyFile="$(MSBuildExtensionsPath)\DuplicateFinder.Tasks.dll" />

  <ItemGroup>
    <TestFiles 
	  Include="..\..\**\*.cs"  
	  Exclude="..\..\**\AssemblyInfo.cs"  
	/>
  </ItemGroup>
  <Target Name="RunTest">
    <DuplicateFinder 
      Files="@(TestFiles)"
      DuplicateThreshold="3"
      FocusFile="Text1.txt"
      FirstLineMinWidth="5"
      CountThresholdForError="3"
      LengthThresholdForError="10"
      CountThresholdForError2="2"
      LengthThresholdForError2="20"
      CountThresholdForError3="1"
      LengthThresholdForError3="30"	
      ExcludedLinePrefixes="using"
     />
  </Target>
</Project>


Here is an example with multiple line prefix exclusions specified on multiple lines:
<DuplicateFinder 
    ExcludedLinePrefixes="
    using
    return
    private" 
    Files="@(TestFiles)" />

Last edited May 4, 2008 at 4:48 PM by AnthonySteele, version 14

Comments

dhavalcharadva Jan 12, 2011 at 1:42 PM 
How to specify output parameter in msbuild task ?