timabell / ssrs-powershell-deploy

PowerShell scripts to deploy a SQL Server Reporting Services project (*.rptproj) to a Reporting Server
MIT License
75 stars 40 forks source link

Fix Error When Only One Item Exists in ItemGroup #28

Closed ChadWLiu closed 2 years ago

ChadWLiu commented 5 years ago

The xml parser treats the child nodes differently while converting to PS objects. It casts it to single XML Element when there is only one child node but an array of objects if more. Hence, it will fail with "no Count property" error when the itemgroup is accessed as $Project.Project.ItemGroup[0].DataSource.Count or $Project.Project.ItemGroup[1].Report.Count when there's only one dataSource/report.

The fix simply convert it into array explicitly beforehand and assign with variable other than accessing directly from $project.

ChadWLiu commented 5 years ago

Two more changes here.

  1. Fix the data source and data set overwrite flag. The xml selectSingleNodes seems to be not working.
  2. Fix the iteration on ItemGroup as the first is not always DataSource. (when shared dataset is used)

P.S. All of these are tested only under VS 2017 project.

robertoandrade commented 5 years ago

29 fixes this in a more elegant way using XML namespaces and looping through the elements regardless of how many are there and in what order.