物业' ServiceManifestVersion'在这个对象上找不到。验证该属性是否存在且可以设置

时间:2017-11-07 06:33:48

标签: xml powershell azure-service-fabric

我想使用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")

设置值时,我收到以下错误:

  

该物业&#39; ServiceManifestVersion&#39;在这个对象上找不到。   验证该属性是否存在且可以设置。

如果我只保留一个节点但是在foreach循环上运行它时出错,那么我能够更新这些值。同时,我能够获取值但不能设置它。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

VSTS的人有一些任务。他们是open source。您可以直接在VSTS或TFS中使用任务,也可以在自己的解决方案中使用代码。 (它的麻省理工学院获得许可)

答案 1 :(得分:1)

将您的foreach更改为:

foreach ($ServiceManifestRef in $ApplicationManifestXml.ApplicationManifest.ServiceManifestImport.ServiceManifestRef)
{
    $ServiceManifestRef.SetAttribute('ServiceManifestVersion', $updatedVersionNumber)
}