我已经将SPFX扩展包部署到了应用目录中。我们需要将此应用程序部署到多个网站集。我尝试了无法运行的powershell,有人可以帮忙吗。
$credentials = Get-Credential
Connect-PnPOnline "URl of the site" -Credentials $credentials
$context = Get-PnPContext
$web = Get-PnPWeb
$context.Load($web)
Invoke-PnPQuery
$ca = $web.UserCustomActions.Add()
$ca.ClientSideComponentId = "2dbe5b9b-72f7-4dbf-bd6d-43e91ae3a7cc"
$ca.Location = "ClientSideExtension.ApplicationCustomizer"
$ca.Name = "reportanissue"
$ca.Title = "my-spfx-client-side-solution"
$ca.Description = "Deploys a custom action with ClientSideComponentId association"
$ca.Update()
$context.Load($web.UserCustomActions)
Invoke-PnPQuery
Write-Host $("deployed")
答案 0 :(得分:1)
根据您的情况,使用租户范围的部署并使用属性来控制扩展应在其上处于活动状态的站点可能更有意义:
"features": [
{
"title": "Application Extension - Deployment of custom action.",
"description": "Deploys a custom action with ClientSideComponentId association",
"id": "[any guid here]",
"version": "1.0.0.0",
"assets": {
"elementManifests": [
"elements.xml",
"clientsideinstance.xml"
]
}
}
]
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ClientSideComponentInstance
Title="MyAppCust"
Location="ClientSideExtension.ApplicationCustomizer"
ComponentId="917a86f2-15c1-403e-bbe1-59c6bd50d1e1"
Properties="{"testMessage":"Test message"}">
</ClientSideComponentInstance>
</Elements>
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Title="MyAppCust"
Location="ClientSideExtension.ApplicationCustomizer"
ComponentId="417feb7a-e193-4072-84b8-52ce58ed024f"
ClientSideComponentProperties="{"testMessage":"Test message"}">
</CustomAction>
</Elements>
allowedSites: string[];
:export interface IAlertPopupApplicationCustomizerProperties {
allowedSites: string[];
}
this.context.pageContext.web.absoluteUrl
在allowedSites内时,才允许功能。 即在onInit()中,如果当前站点不在允许的站点中,我会提早返回(在执行其他查询之前):
@override
public onInit(): Promise<void> {
const absoluteUri = this.context.pageContext.web.absoluteUrl;
// clean up allowed sites
const allowedSites = this.properties.allowedSitesRaw && this.properties.allowedSitesRaw.length
? this.properties.allowedSitesRaw.filter(item => !!item)
: [];
// return early if there are allowed sites specified and the current site is not allowed
if (allowedSites.length && allowedSites.indexOf(absoluteUri) == -1) {
return;
}
}
gulp clean && gulp bundle && gulp package-solution --ship
{
allowedSites: [
"https://contoso.sharepoint.com/sites/mySite"
],
testMessage: "Test message"
}