【问题标题】:Update-PnPApp to deploy SharePoint application to SharePoint CatalogUpdate-PnPApp 将 SharePoint 应用程序部署到 SharePoint 目录
【发布时间】:2021-01-24 21:32:06
【问题描述】:

我正在考虑使用 PnP PowerShell 命令将 SharePoint 应用程序部署到 SharePoint 目录。

我能够成功地将包部署到应用目录。我现在正在创建一个脚本来自动化在我的网站上安装解决方案的过程:

我创建了一个脚本如下:

   Add-PnPApp -Path $Path -Scope Tenant -Overwrite -Publish
   $packageInSite = Add-PnPApp -Path $Path -Scope Site -Overwrite -Publish
   Publish-PnPApp -Identity $packageInSite.Id -Scope Site         
   if ($packageInSite.InstalledVersion -eq $null) {
        Write-Verbose "Installing app..."
        Install-PnPApp -Identity $packageInSite.Id -Scope Site 
   }
  elseif ($packageInSite.CanUpgrade -eq $true) {
       Write-Verbose "Updating installed app..."
       Update-PnPApp -Identity $packageInSite.Id -Scope Site
   }
  else {
   throw 'Version ' + $packageInSite.AppCatalogVersion + ' already exists.'
  }

在运行上述脚本时,我看到以下错误:

Error:
{"odata.error":{"code":"-2146232832, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The app for SharePoint with ID dd996c57-c36f-425a-8ede-bd77bfd24433 does not exist in the app catalog."}}}
At C:\Source...\Publish-PnPAppToAppCatalog.ps1:73 char:9
Update-PnPApp -Identity $packageInSite.Id -Scope Site
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : WriteError: (:) [Update-PnPApp], Exception
FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Apps.UpdateApp

但是,当我运行 Get-PnpApp -Scope Site 命令时,我发现应用程序站点目录中存在该应用程序。

我错过了什么?

更新:

我更新代码如下:

    Connect-PnPOnline -Url "https://<tenant>.sharepoint.com" -Credentials $credential -TenantAdminUrl "https://<tenant>-admin.sharepoint.com"
    Add-PnPApp -Path $Path -Scope Tenant -Overwrite -Publish
    
    Add-PnPSiteCollectionAppCatalog -Site "https://<tenant>.sharepoint.com/sites"

    $packageInSite = Add-PnPApp -Path $Path -Scope Site -Overwrite -Publish
    Publish-PnPApp -Identity $packageInSite.Id -Scope Site
   
    if ($packageInSite.InstalledVersion -eq $null) {
        Write-Verbose "Installing app..."
        Install-PnPApp -Identity $packageInSite.Id -Scope Site 
    } elseif ($packageInSite.CanUpgrade -eq $true) {
        Write-Verbose "Updating installed app..."
        Update-PnPApp -Identity $packageInSite.Id -Scope Site
    } else {
        throw 'Version ' + $packageInSite.AppCatalogVersion + ' already exists.'
    }

这给出了一个错误:

Add-PnPSiteCollectionAppCatalog : The list item could not be added or updated because duplicate values were found in the following field(s) in the list: [Site Collection Id].
At ###.ps1:55 char:5
+     Add-PnPSiteCollectionAppCatalog -Site "https://<tenant>.sharep ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Add-PnPSiteCollectionAppCatalog], ServerException
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Admin.AddSiteCollectionAppCatalog

【问题讨论】:

    标签: powershell sharepoint sharepoint-online


    【解决方案1】:

    您可以尝试启用网站集应用程序目录:

    Connect-PnPOnline (TenantSite URL)
    Add-PnPSiteCollectionAppCatalog -Site (SiteCollection URL)
    

    这里有一个类似的问题供您参考:

    https://github.com/pnp/PnP-PowerShell/issues/2611

    【讨论】:

    • 谢谢!我应该在代码的第一行之前添加上述 2 个命令吗?
    • 另外,您能否举一个 SiteCollection URL 的示例?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-06
    • 1970-01-01
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    相关资源
    最近更新 更多