trying to find all *.config files which contain specific assembly info. In my case, I want to find all config files which has System.Net.Http
with version 4.0.0.0
this is how the example content looks like:
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf38564e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-999.999.999.999" newVersion="5.2.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f750a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-999.999.999.999" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bfad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-999.999.999.999" newVersion="4.0.0.0" />
</dependentAssembly>
so I need the location of that config file which
starts with: <assemblyIdentity name="System.Net.Http"
AND
ends with: newVersion="4.0.0.0"
which are in same dependentAssembly
the lines can have nasty empty spaces before and at the end of line some line endings (\r\n)
appreciate any help!
This is what I have tried:
$dDir = Get-ChildItem -Recurse -File -Filter "*.config" -ErrorAction SilentlyContinue
$dDir | ?{$_ | Select-String -Pattern "System.Net.Http"} | ?{$_ | Select-String -Pattern "newVersion=\`"4.0.0.0\`""} | select fullname
but this also returns if the newVersion="4.0.0.0"
was found in different dependentAssembly
So I tried using regex (regex noob):
$dDir | ?{$_ | Select-String -Pattern '(.*)\<assemblyIdentity name=\"System.Net.Http\"(.*)newVersion=\"4.0.0.0\"(.*)' -AllMatches}
but this return nothing