2016-05-12 8 views
0

PowerShellスクリプトでSPFeature.Upgrade(false)メソッドを呼び出すスクリプトがあります。 C#のFeatureUpgradingメソッドの中で、アップグレードをシミュレートするための例外をスローしています。ただし、アップグレードは正常に実行され、機能バージョンはアップグレードされます。例外発生時にSharePoint機能がアップグレードされないようにするにはどうすればよいですか?ここで私が持っているものです。SharePoint機能のアップグレード時にエラーが発生する

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 
     } 
    } 

//パワーシェルスクリプト

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) 
} 

どれをアップグレード

// 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#の機能助けが大いに評価されるだろう!

答えて

0

アップグレードを中止するために、C#catchブロックでエラーを再度スローする必要がありました。

catch (Exception p_ex) 
    { 
     // Log message to SharePoint logs 
     Throw p_ex; 
    } 
関連する問題