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

Works correctly only if a .rptproj file contains more then one Report and DataSource #26

Open PavelSamoilenko opened 5 years ago

PavelSamoilenko commented 5 years ago

Who faced to with the same limitations.

Error in PowerShell if only one item in XML (one report or one DataSource): Publish-SSRSProject : The property 'Count' cannot be found on this object. Verify that the property exists

Error, if there are not DataSources in the rpproj file: Publish-SSRSProject : The property 'DataSource' cannot be found on this object. Verify that the property exists.

You should add at least two items for every node:

  <ItemGroup>
    <Report Include="TestReport1.rdl" />
    <Report Include="TestReport2.rdl" />
  </ItemGroup>  
  <ItemGroup>
    <DataSource Include="SharedDataSourceTest.rds" />
    <DataSource Include="SharedDataSourceTest2.rds" />
  </ItemGroup>

Via Visual Studio: image

Error here: image (before merge https://github.com/timabell/ssrs-powershell-deploy/pull/25)

Would be grate if anybody remove these limitations.

vminds commented 5 years ago

Hi, I experienced the same problem. Seems like the dotted notation is unreliable. When using selectNodes it is working, also when only one DataSet/Report. However it only works when the schema xmlns attribute is not referenced in the root element, unless using an XmlNamespaceManager Not sure if that is a good solution, I need to do some more reading and tests on it. I welcome feed back :)

$ns = New-Object System.Xml.XmlNamespaceManager($Project.NameTable)
    $ns.AddNamespace("msbld", $Project.DocumentElement.NamespaceURI)

    $DataSourcePaths = @{}
    $Project.SelectNodes("//msbld:DataSource", $ns) |
       ForEach-Object {
          $RdsPath = $ProjectRoot | Join-Path -ChildPath $_.Include
          $DataSource = New-SSRSDataSource -Proxy $Proxy -RdsPath $RdsPath -Folder $DataSourceFolder -Overwrite $OverwriteDataSources
          $DataSourcePaths.Add($DataSource.Name, $DataSource.Path)
       }

https://blogs.technet.microsoft.com/georgewallace/2014/11/13/using-selectsinglenode-in-powershell-with-xml-namespace-azure-vnetconfig/

christophpre commented 5 years ago

@vminds I tried your solution and it works fine for the DataSources. Would be cool if you could come up with a PR that includes the Report.Count path as well.

vminds commented 5 years ago

I did add some more features such as removing datasource/reports using the Microsoft/ReportingServicesTools. Need to finalize and generalize the code and plan to add it as a fork of this repo.