Reputation: 163
I need to update this config file in such a way that, all the values of 'newVersion' needs to be updated to a single value.
<configuration>
<runtime>
<assemblyBinding>
<dependentAssembly>
<assemblyIdentity name="A"
publicKeyToken="5d861ad8ad8cd06f" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65534.65534.65534.65534" newVersion="4.0.0.103" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="B" publicKeyToken="ae714df8cd90bc8f" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65534.65534.65534.65534" newVersion="4.0.0.103" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="C" publicKeyToken="22955931b98512b6" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65534.65534.65534.65534" newVersion="4.0.0.103" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="D"
publicKeyToken="585a888b4a9ba2e3"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65534.65534.65534.65534"
newVersion="2.5.0.1286"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
I have tried this below
$appconfig='file location'
$doc = (Get-Content $appconfig) -as [Xml]
$obj = $doc.configuration.runtime.assemblyBinding.dependentAssembly
$obj2 = $obj.assemblyIdentity | where {$_.name -eq 'D'}
$obj.bindingRedirect.newVersion="1.1.1.1"
echo $obj.bindingRedirect.newVersion
$doc.Save($appconfig)
I know this would change only to the "D" part, how can change to the above A,B and C also. Thanks for your help !
Upvotes: 0
Views: 477
Reputation: 26120
(gc C:\temp\config.xml) -replace '(newversion=)".*?"' ,'$1"1.1.1.1"' # if you want to save the file add |sc c:\temp\config.xml
Upvotes: 1