Skip to content

Instantly share code, notes, and snippets.

@kstrauss
Created May 11, 2015 15:44
Show Gist options
  • Save kstrauss/afb52c52923fecf2e88d to your computer and use it in GitHub Desktop.
Save kstrauss/afb52c52923fecf2e88d to your computer and use it in GitHub Desktop.
Search & replace package hintpaths with the solutionDir variable.
dir -recurse -filter *.csproj | ReplaceText-InFile -searchPattern "<HintPath>(.*)\\packages" -replaceText "<HintPath>`$(SolutionDir)\packages"
Param(
[parameter(Mandatory=$true,ValueFromPipeline=$true)]
[System.IO.FileInfo] $inputFile,
[Parameter(Mandatory=$true)]
[String] $searchPattern,
[Parameter(Mandatory=$true)]
[String] $replaceText
)
Begin{}
Process{
$x=gc $inputFile.FullName;
$y=$x -replace $searchPattern, $replaceText;
#only replace those that there actually were changes
if (Compare-Object $x $y)
{
$y | Out-File -Encoding UTF8 -FilePath $inputFile.FullName
}
}
End{}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment