[英]SharePoint Feature upgrade error catching
我有一個PowerShell腳本,而不是調用SPFeature.Upgrade(false)方法。 然后在c#中的FeatureUpgrading方法中,我拋出了異常以模擬升級失敗。 但是,升級仍成功執行,並且功能版本已升級。 發生異常時,如何防止SharePoint功能升級? 這是我所擁有的:
// feature.template.template.xml
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/" Version="$SharePoint.Project.AssemblyVersion$">
<UpgradeActions>
<VersionRange BeginVersion="0.0.0.0">
<CustomUpgradeAction Name="AllUpgrades" />
<ApplyElementManifests>
<ElementManifest Location="test\Elements.xml" />
</ApplyElementManifests>
</VersionRange>
</UpgradeActions>
</Feature>
// c#功能升級
public override void FeatureUpgrading(SPFeatureReceiverProperties p_properties, string p_upgradeActionName, System.Collections.Generic.IDictionary<string, string> p_parameters)
{
try
{
SPWeb parentWeb = p_properties.Feature.Parent as SPWeb;
using (SPSite site = new SPSite(parentWeb.Url, parentWeb.Site.SystemAccount.UserToken))
{
using (SPWeb web = site.OpenWeb())
{
switch (p_upgradeActionName)
{
case "AllUpgrades":
throw new Exception("Simulate failure");
}
}
}
}
catch (Exception p_ex)
{
// Log message to SharePoint logs
}
}
// Power Shell腳本
Add-PSSnapin Microsoft.SharePoint.PowerShell
$web = Get-SPWeb "http://myURL"
$featureName = "featureName"
feature = $web.Features|Where {$_.Definition.DisplayName -eq $featureName}
try
{
// I would expect this call to fail and return exception from c#, but it doesn't. instead feature upgrade just fine
$feature.Upgrade($false)
}
catch [Exception]
{
Write-Host ($_.Exception.Message)
}
任何幫助將不勝感激!
我不得不在c#catch塊中再次拋出錯誤,以使升級停止。
catch (Exception p_ex)
{
// Log message to SharePoint logs
Throw p_ex;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.