Last active
July 23, 2022 19:59
-
-
Save badmotorfinger/f6aaef93bc01345c2bbf60f175568863 to your computer and use it in GitHub Desktop.
Use ReSharper command line tool dupFinder to produce a report of duplicated C# code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$reportFileName = 'dupfinder.html' | |
$dupFindLocation = 'C:\dev\tools\ReSharperCliTools\dupfinder.exe' | |
if (-not (Test-Path $dupFindLocation)) { | |
Write-Host "dupfinder.exe not found in path $dupFindLocation" | |
Write-Host "Download tools from https://www.jetbrains.com/help/resharper/2017.1/ReSharper_Command_Line_Tools.html" | |
exit | |
} | |
$xsl = '<?xml version="1.0" encoding="utf-8"?> | |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> | |
<xsl:output method="html" indent="yes" /> | |
<xsl:template match="/"> | |
<html> | |
<body> | |
<h1>Statistics</h1> | |
<p>Total codebase size: <xsl:value-of select="//CodebaseCost"/></p> | |
<p>Code to analyze: <xsl:value-of select="//TotalDuplicatesCost"/></p> | |
<p>Total size of duplicated fragments: <xsl:value-of select="//TotalFragmentsCost" /></p> | |
<h1>Detected Duplicates</h1> | |
<xsl:for-each select="//Duplicates/Duplicate"> | |
<xsl:if test="(@Cost > 100 and @Cost < 400)"> | |
<h2>Duplicated Code. Size: <xsl:value-of select="@Cost"/></h2> | |
<h3>Duplicated Fragments:</h3> | |
<xsl:for-each select="Fragment"> | |
<xsl:variable name="i" select="position()"/> | |
<p>Fragment <xsl:value-of select="$i"/> in file <xsl:value-of select="FileName"/></p> | |
<pre><xsl:value-of select="Text"/></pre> | |
</xsl:for-each> | |
</xsl:if> | |
</xsl:for-each> | |
</body> | |
</html> | |
</xsl:template> | |
</xsl:stylesheet>' | |
$XSLInputElement = New-Object System.Xml.Xsl.XslCompiledTransform; | |
$tmpXsl = [System.IO.Path]::GetTempFileName(); | |
Set-Content -Path $tmpXsl -Value $xsl; | |
$XSLInputElement.Load($tmpXsl) | |
$currentDir = Split-Path $MyInvocation.MyCommand.Definition | |
Set-Location $currentDir | |
& $dupFindLocation "**\*.cs" -o='dupfinder.xml' -e='**\*.designer.cs;**\*Tests*;**\*.generated.cs;**\Reference.cs;**\generated.cs;**\App.xaml.cs;**\*samples;**\AssemblyInfo.cs' --show-text --discard-cost=20 | |
$XSLInputElement.Transform("$currentDir\dupfinder.xml", "$currentDir\$reportFileName") | |
Write-Host "`nWrote HTML report to $currentDir\$reportFileName`n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment