0

I am trying, withouth much luck, to create a bat or cmd file that would change a "corrupt" hintpath of my third party dll's so that it referes to my fixed dll path (the P-drive). The script would have to: 1) loop through all folders under my main projects folder finding all files with the .csproj ending 2) loop through each file and replace every instance of "< HintPath >c:\xx\yy\q.dll< /HintPath >" to "< HintPath >P:\q.dll< /HintPath >"

thanks,

regards, styrmir

styrmiro
  • 11
  • 2

1 Answers1

2

If possible, I would highly suggest to use PowerShell to perform this task. Here is what it would take to do what you are after:

Get-ChildItem -Recurse -Filter *.csproj -Path YOUR_TARGET_ROOT_DIRECTORY_HERE |
    ForEach-Object {
        (Get-Content $_.FullName) |
        ForEach-Object {
            $_.Replace('<HintPath>c:\xx\yy\q.dll</HintPath>', '<HintPath>P:\q.dll</HintPath>')
        } |
        Set-Content $_.FullName -WhatIf
    }

Note: I have included a -WhatIf switch that prevents the script to make any change and just outputs the actions it would perform to the console window. Please remove it to make the script functional.

UPDATE

To replace every possible HintPath reference to q.dll within C:, at every possible directory depth, you may replace this line:

$_.Replace('<HintPath>c:\xx\yy\q.dll</HintPath>', '<HintPath>P:\q.dll</HintPath>')

with this one:

$_ -replace '\<HintPath\>C:\\.*\\q.dll\</HintPath\>', '<HintPath>P:\q.dll</HintPath>'
Efran Cobisi
  • 6,138
  • 22
  • 22
  • thanks for the reply. I am going to try this using the powershell. Just out of curiosity, do you know how I would alter the suggested script so that \xx\yy are wildcards of different length - i.e. some paths might be c:\xx\yy\q.dll while others might be c:\zz\rr\mm\dd\o.dll? – styrmiro Aug 30 '11 at 19:43
  • You are welcome, I have updated my reply to match your new answer. – Efran Cobisi Aug 31 '11 at 05:30