styrmiro
styrmiro

Reputation: 11

Cmd script to set the hintpath in .net projects

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

Upvotes: 0

Views: 616

Answers (1)

Efran Cobisi
Efran Cobisi

Reputation: 6464

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>'

Upvotes: 2

Related Questions