1
我有一個要求運行時節點下的條目的XML文件(以紅色突出顯示)添加相同的條目上的xml:不要通過PowerShell命令
我能夠通過以下PowerShell來實現這一目標腳本
$appFrameContainerAppConfig = 'D:\H.Infrastructure.AppFrame.Container.exe.config'
$doc = (Get-Content $appFrameContainerAppConfig) -as [Xml]
$root = $doc.get_DocumentElement()
$newDependentAssembly = $doc.CreateElement("dependentAssembly")
$newAssemblyIdentity = $doc.CreateElement("assemblyIdentity")
$newAssemblyIdentity.SetAttribute("name","EntityFramework")
$newAssemblyIdentity.SetAttribute("publicKeyToken","b77a5c561934e089")
$newAssemblyIdentity.SetAttribute("culture","neutral")
$newDependentAssembly.AppendChild($newAssemblyIdentity)
$newCodeBase = $doc.CreateElement("codeBase")
$newCodeBase.SetAttribute("version","6.0.0.0")
$newCodeBase.SetAttribute("href","EntityFramework_6.1.3/EntityFramework.dll")
$newDependentAssembly.AppendChild($newCodeBase)
$root.runtime.assemblyBinding.AppendChild($newDependentAssembly)
$newDependentAssembly = $doc.CreateElement("dependentAssembly")
$newAssemblyIdentity = $doc.CreateElement("assemblyIdentity")
$newAssemblyIdentity.SetAttribute("name","EntityFramework.SqlServer")
$newAssemblyIdentity.SetAttribute("publicKeyToken","b77a5c561934e089")
$newAssemblyIdentity.SetAttribute("culture","neutral")
$newDependentAssembly.AppendChild($newAssemblyIdentity)
$newCodeBase = $doc.CreateElement("codeBase")
$newCodeBase.SetAttribute("version","6.0.0.0")
$newCodeBase.SetAttribute("href","EntityFramework_6.1.3/EntityFramework.SqlServer.dll")
$newDependentAssembly.AppendChild($newCodeBase)
$root.runtime.assemblyBinding.AppendChild($newDependentAssembly)
$newDependentAssembly = $doc.CreateElement("dependentAssembly")
$newAssemblyIdentity = $doc.CreateElement("assemblyIdentity")
$newAssemblyIdentity.SetAttribute("name","System.Data.SQLite")
$newAssemblyIdentity.SetAttribute("publicKeyToken","db937bc2d44ff139")
$newAssemblyIdentity.SetAttribute("culture","neutral")
$newDependentAssembly.AppendChild($newAssemblyIdentity)
$newCodeBase = $doc.CreateElement("codeBase")
$newCodeBase.SetAttribute("version","1.0.98.0")
$newCodeBase.SetAttribute("href","SQLite_1.0.98.1/System.Data.SQLite.dll")
$newDependentAssembly.AppendChild($newCodeBase)
$root.runtime.assemblyBinding.AppendChild($newDependentAssembly)
$newDependentAssembly = $doc.CreateElement("dependentAssembly")
$newAssemblyIdentity = $doc.CreateElement("assemblyIdentity")
$newAssemblyIdentity.SetAttribute("name","System.Data.SQLite.EF6")
$newAssemblyIdentity.SetAttribute("publicKeyToken","db937bc2d44ff139")
$newAssemblyIdentity.SetAttribute("culture","neutral")
$newDependentAssembly.AppendChild($newAssemblyIdentity)
$newCodeBase = $doc.CreateElement("codeBase")
$newCodeBase.SetAttribute("version","1.0.98.0")
$newCodeBase.SetAttribute("href","SQLite_1.0.98.1/System.Data.SQLite.EF6.dll")
$newDependentAssembly.AppendChild($newCodeBase)
$root.runtime.assemblyBinding.AppendChild($newDependentAssembly)
$newDependentAssembly = $doc.CreateElement("dependentAssembly")
$newAssemblyIdentity = $doc.CreateElement("assemblyIdentity")
$newAssemblyIdentity.SetAttribute("name","System.Data.SQLite.Linq")
$newAssemblyIdentity.SetAttribute("publicKeyToken","db937bc2d44ff139")
$newAssemblyIdentity.SetAttribute("culture","neutral")
$newDependentAssembly.AppendChild($newAssemblyIdentity)
$newCodeBase = $doc.CreateElement("codeBase")
$newCodeBase.SetAttribute("version","1.0.98.0")
$newCodeBase.SetAttribute("href","SQLite_1.0.98.1/System.Data.SQLite.Linq.dll")
$newDependentAssembly.AppendChild($newCodeBase)
$root.runtime.assemblyBinding.AppendChild($newDependentAssembly)
Write-Output $root.runtime.assemblyBinding.dependentAssembly
$doc.Save($appFrameContainerAppConfig)
我需要其評估如果條目以紅色突出顯示存在於XML若然避免添加相同的條件。
if($root.SelectNodes('//configuration/runtime/assemblyBinding/dependentAssembly/assemblyIdentity[@name="EntityFramework"]')) {
} else {
}
我在這裏使用的條件似乎不起作用。它不會進入內部,如果或條件。有什麼建議麼?
這不工作,我仍然最終以創建重複的條目。事實上它根本不會進入if循環 –
「不工作」是一個不充分的問題描述。請編輯你的問題並提供證據。 –
我的意思是if循環沒有得到執行,我寫了一些寫入輸出,如果循環沒有執行 –