Mohit chhabra
Mohit chhabra

Reputation: 123

The property 'ServiceManifestVersion' cannot be found on this object. Verify that the property exists and can be set

I want to update the XML file using the Powershell. I want to update the ServiceManifestVersion to some value.

`<?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>`

I am trying to update the values by using the following Code

$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")

While Setting the value I am getting the following error:

The property 'ServiceManifestVersion' cannot be found on this object. Verify that the property exists and can be set.

If I am able to update the values if I am keeping only one node but getting the error while running it on foreach loop.Also, I am able to get the values but not set it. Any help will be appreciated.

Upvotes: 0

Views: 1377

Answers (2)

fdafadf
fdafadf

Reputation: 819

Change your foreach to:

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

Upvotes: 1

LoekD
LoekD

Reputation: 11470

The VSTS guys have some Tasks for this. They're open source. You can use the tasks directly in VSTS or TFS, or use the code in your own solution. (it's MIT licensed)

Upvotes: 1

Related Questions