我有一个PowerShell脚本,而不是调用SPFeature.Upgrade(false)方法。然后,在FeatureUpgrading方法中的c#中,我抛出一个异常来模拟升级失败。但是,升级仍然成功执行,功能版本也得到了升级。当发生异常时,如何防止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)
}任何帮助都将不胜感激!
发布于 2016-05-23 14:56:31
为了使升级停止,我不得不在c# catch块中再次抛出错误。
catch (Exception p_ex)
{
// Log message to SharePoint logs
Throw p_ex;
}https://stackoverflow.com/questions/37198262
复制相似问题