【问题标题】:The property 'ServiceManifestVersion' cannot be found on this object. Verify that the property exists and can be set在此对象上找不到属性“ServiceManifestVersion”。验证该属性是否存在并且可以设置
【发布时间】: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


    【解决方案1】:

    将你的 foreach 更改为:

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

    【讨论】:

      【解决方案2】:

      VSTS 人员为此设置了一些任务。他们是open source。您可以直接在 VSTS 或 TFS 中使用任务,也可以在自己的解决方案中使用代码。 (它是 MIT 许可的)

      【讨论】:

      • 这也会有所帮助。我需要对其进行一些调整才能与 Bamboo 一起使用,但它会帮助我。感谢您的帮助:)
      猜你喜欢
      • 2021-10-22
      • 2022-12-24
      • 1970-01-01
      • 2011-02-11
      • 2021-04-24
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 2011-07-24
      相关资源
      最近更新 更多