0
<configuration>
  <runtime>
    <assemblyBindings>
      <dependentAssemblyss>
        <assemblyIdentity name="A" publicKeyToken="5d861ad8ad8cd06f" culture="neutral" />
        <bindingRedirects oldVersion="0.0.0.0-68834.68834.68834.68834" newVersion="4.5.0.103" />
      </dependentAssemblys>
      <dependentAssembly>
        <assemblyIdentity name="B" publicKeyToken="ae714df8cd90bc8f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-65534.65534.65534.65534" newVersion="3.0.0.103" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="C" publicKeyToken="22955931b98512b6" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-65534.65534.65534.65534" newVersion="8.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 already posted this and got the answer for this question... I could have posted this new question as comment to that, but due to chars restrictions I am posting it here

How can change newVersion value? A, B will have 0.0.0.1 and C,D will have 0.0.0.2 Thanks !!

1

1 Answer 1

0

PowerShell is pretty flexible when working with [Xml] types. In the following example I'm reading in your xml from above (fixed some xml format errors), then using an array of hashes ($replacements) to specify which named dependent assemblies should have which newVersion values.

[Xml]$doc = @"
<configuration>
  <runtime>
    <assemblyBindings>
      <dependentAssembly>
        <assemblyIdentity name="A" publicKeyToken="5d861ad8ad8cd06f" culture="neutral" />
        <bindingRedirects oldVersion="0.0.0.0-68834.68834.68834.68834" newVersion="4.5.0.103" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="B" publicKeyToken="ae714df8cd90bc8f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-65534.65534.65534.65534" newVersion="3.0.0.103" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="C" publicKeyToken="22955931b98512b6" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-65534.65534.65534.65534" newVersion="8.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>
    </assemblyBindings>
  </runtime>
</configuration>
"@
$replacements =@(@{'name'='C'; 'newVersion'='0.0.1'},@{'name'='D'; 'newVersion'='0.0.3'})
foreach($replacement in $replacements)
{
  $doc.configuration.runtime.assemblyBindings.dependentAssembly | `
     Where-Object -FilterScript {$_.assemblyIdentity.name -eq $replacement.name} |% `
     {$_.bindingRedirect.newVersion = $replacement.newVersion}
}
#Output the raw xml to show the changes:
write-host $doc.OuterXml

The foreach is iterating through the elements in $replacements, and then finding the matching dependentAssembly by its assemblyIdentity.name, and then updating the newVersion value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.