【发布时间】:2017-11-07 16:44:29
【问题描述】:
我想使用 Powershell 更新 XML 文件。我想将 ServiceManifestVersion 更新为某个值。
`<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="AvatarPoc.FabricType" ApplicationTypeVersion="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="AzureCosmosMongoDbConnectionString" DefaultValue="WillBeSetBeforeDeployment" />
<Parameter Name="AzureServiceBusConnectionString" DefaultValue="WillBeSetBeforeDeployment" />
<Parameter Name="AzureAppInsightsInstrumentationKey" DefaultValue="WillBeSetBeforeDeployment" />
<Parameter Name="SignalRAzureServiceBusTopicPrefix" DefaultValue="WillBeSetBeforeDeployment" />
<Parameter Name="SignalREncryptionKey" DefaultValue="WillBeSetBeforeDeployment" />
</Parameters>
<!-- Import the ServiceManifest from the ServicePackage. The ServiceManifestName and ServiceManifestVersion should match the Name and Version attributes of the ServiceManifest element defined in the ServiceManifest.xml file. -->
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="AvatarPoc.AudioDeviceActorPkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides>
<ConfigOverride Name="Config">
<Settings>
<Section Name="AppConfig">
<Parameter Name="AzureCosmosMongoDbConnectionString" Value="[AzureCosmosMongoDbConnectionString]" />
<Parameter Name="AzureAppInsightsInstrumentationKey" Value="[AzureAppInsightsInstrumentationKey]" />
</Section>
</Settings>
</ConfigOverride>
</ConfigOverrides>
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="AvatarPoc.PubSubActorPkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides>
<ConfigOverride Name="Config">
<Settings>
<Section Name="AppConfig">
<Parameter Name="AzureServiceBusConnectionString" Value="[AzureServiceBusConnectionString]" />
<Parameter Name="SignalRAzureServiceBusTopicPrefix" Value="[SignalRAzureServiceBusTopicPrefix]" />
<Parameter Name="SignalREncryptionKey" Value="[SignalREncryptionKey]" />
<Parameter Name="AzureAppInsightsInstrumentationKey" Value="[AzureAppInsightsInstrumentationKey]" />
</Section>
</Settings>
</ConfigOverride>
</ConfigOverrides>
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="AvatarPoc.SignalPkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides>
<ConfigOverride Name="Config">
<Settings>
<Section Name="AppConfig">
<Parameter Name="AzureServiceBusConnectionString" Value="[AzureServiceBusConnectionString]" />
<Parameter Name="SignalRAzureServiceBusTopicPrefix" Value="[SignalRAzureServiceBusTopicPrefix]" />
<Parameter Name="SignalREncryptionKey" Value="[SignalREncryptionKey]" />
<Parameter Name="AzureAppInsightsInstrumentationKey" Value="[AzureAppInsightsInstrumentationKey]" />
</Section>
</Settings>
</ConfigOverride>
</ConfigOverrides>
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="AvatarPoc.WebApiPkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides>
<ConfigOverride Name="Config">
<Settings>
<Section Name="AppConfig">
<Parameter Name="AzureCosmosMongoDbConnectionString" Value="[AzureCosmosMongoDbConnectionString]" />
<Parameter Name="AzureAppInsightsInstrumentationKey" Value="[AzureAppInsightsInstrumentationKey]" />
</Section>
</Settings>
</ConfigOverride>
</ConfigOverrides>
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="AvatarPoc.ThingListenerPkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides>
<ConfigOverride Name="Config">
<Settings>
<Section Name="AppConfig">
<Parameter Name="AzureCosmosMongoDbConnectionString" Value="[AzureCosmosMongoDbConnectionString]" />
<Parameter Name="AzureAppInsightsInstrumentationKey" Value="[AzureAppInsightsInstrumentationKey]" />
</Section>
</Settings>
</ConfigOverride>
</ConfigOverrides>
</ServiceManifestImport>
<ServiceTemplates>
<StatefulService ServiceTypeName="AudioDeviceActorServiceType">
<UniformInt64Partition PartitionCount="1" LowKey="-9223372036854775808" HighKey="9223372036854775807" />
</StatefulService>
<StatefulService ServiceTypeName="PubSubActorServiceType">
<UniformInt64Partition PartitionCount="1" LowKey="-9223372036854775808" HighKey="9223372036854775807" />
</StatefulService>
<StatelessService ServiceTypeName="SignalType">
<SingletonPartition />
</StatelessService>
<StatelessService ServiceTypeName="WebApiType">
<SingletonPartition />
</StatelessService>
<StatefulService ServiceTypeName="ThingListenerType">
<UniformInt64Partition PartitionCount="4" LowKey="0" HighKey="3" />
</StatefulService>
</ServiceTemplates>
</ApplicationManifest>`
我正在尝试使用以下代码更新值
$buildNo = "001"
$ApplicationManifestPath = "D:\New folder\new1.xml"
$ApplicationManifestString = [string] (Get-Content $ApplicationManifestPath)
$ApplicationManifestXml = [xml]$ApplicationManifestString
$applicationTypeVersionOld = [string]$ApplicationManifestXml.ApplicationManifest.ApplicationTypeVersion
$updatedVersionNumber =[string] $applicationTypeVersionOld + "-" + $buildNo
$ServiceManifestVersions = $ApplicationManifestXml.ApplicationManifest.ServiceManifestImport.ChildNodes
foreach($ServiceManifestversion in $ServiceManifestVersions)
{
$ApplicationManifestXml.ApplicationManifest.ServiceManifestImport.ServiceManifestRef.ServiceManifestVersion = $updatedVersionNumber
}
$ApplicationManifestXml.Save("D:\New Folder\new 2 .xml")
设置值时出现以下错误:
在此对象上找不到属性“ServiceManifestVersion”。 验证该属性是否存在并且可以设置。
如果我只保留一个节点但在 foreach 循环上运行它时出现错误,我能够更新这些值。此外,我能够获取值但不能设置它。任何帮助将不胜感激。
【问题讨论】:
标签: xml powershell azure-service-fabric