2012-07-04 49 views
2

假設我有一個SP2010解決方案,它可以完成許多操作:創建內容類型,實例化列表,添加事件接收器,網絡,以及整個組合。現在讓我們說我開發新的東西:更改一些內容類型,更改一些事件接收器等。現有的列表不會受到任何影響。這是我猜的一個給定的,但我需要應用到處的變化。你將如何處理解決方案更新很好?SharePoint 2010手柄解決方案更新

我知道SharePoint有一個升級框架(請參閱SPPersistedUpgradableObject.NeedsUpgrade),但我認爲它適用於SharePoint產品本身的升級。

那該怎麼辦?將當前版本號存儲在某個地方的一個屬性包中,掛接一個功能激活的事件接收器,遍歷整個世界(webapps,網站,網絡,列表...)並升級所有內容?必須有一些框架來幫助我,如果沒有別的,那麼至少應該在某處顯示進度條,因爲它可能需要5分鐘或更長的時間。所有想法都歡迎。

回答

6

這是我如何做到這一點:

之前部署我更新的功能,我打開Visual Studio中的功能和更改版本屬性(當我創建新的功能,我的版本設置爲1.0.0.0)。接下來,我單擊Manifest按鈕,展開編輯選項部分,然後輸入UpgradeActions數據。

下面是一個略加修改的版本升級後的功能:

<?xml version="1.0" encoding="utf-8" ?> 
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"> 
<UpgradeActions> 
    <VersionRange BeginVersion="1.0.0.0" EndVersion="1.1.0.0"> 
    <CustomUpgradeAction Name="UpgradeTo1v1" /> 
    </VersionRange> 
    <VersionRange BeginVersion="1.1.0.0" EndVersion="1.3.0.0"> 
    <CustomUpgradeAction Name="UpgradeTo1v3" /> 
    </VersionRange> 
    <VersionRange BeginVersion="1.3.0.0" EndVersion="1.4.0.0"> 
    <CustomUpgradeAction Name="UpgradeTo1v4"> 
    <Parameters> 
    <Parameter Name="OptionalParameter">Values go here</Parameter> 
    </Parameters> 
    </CustomUpgradeAction> 
    </VersionRange> 
</UpgradeActions> 
</Feature> 

我再添加或修改我的功能接收器的FeatureUpgrading方法:

[SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)] 
public override void FeatureUpgrading(
    SPFeatureReceiverProperties properties, 
    string upgradeActionName, 
    System.Collections.Generic.IDictionary<string, string> parameters) 
{ 
    SPSite site = properties.Feature.Parent as SPSite; 
    SPWeb web = site.RootWeb; 
    switch (upgradeActionName) 
    { 
     case "UpgradeTo1v1": 
      UpgradeTo1v1(site, properties, parameters); 
      break; 
     case "UpgradeTo1v3": 
      UpgradeTo1v3(site, properties, parameters); 
      break; 
     case "UpgradeTo1v4": 
      UpgradeTo1v4(site, properties, parameters); 
      break; 
    } 
} 

我的私人升級方法作任何以編程方式進行更改,這些更新後的解決方案軟件包部署時不會自動實現。我部署使用下面的PowerShell腳本解決方案包:

Write-Host "Upgrading solution: $SolutionPackageName" -NoNewline 
Update-SPSolution -Identity $SolutionPackageName -LiteralPath $SolutionPackagePath -GACDeployment -Confirm:$false -Force 
while ($Solution.JobExists) 
{ 
    Start-Sleep -s 2 
} 
Write-Host " - Done." 

if ($UpdateFeatureGuids -ne $null) 
{ 
    foreach ($site in Get-SPSite -Limit All) 
    { 
     $UpdateFeatureGuids | % { $site.QueryFeatures([Guid]$_, [bool]$true) } | % { 
      $definitionId = $_.DefinitionId 
      $parentUrl = $_.Parent.Url 
      Write-Host "Upgrading feature: $definitionId $parentUrl" 
      $_.Upgrade([bool]$false) | % { 
       if ($_ -ne $null) 
       { 
        Format-List -InputObject $_ -Property Message, InnerException -Force 
       } 
      } 
      Write-Host "Upgrading feature: $definitionId $parentUrl - Done." 
     } 
     $site.Dispose() 
    } 
} 

我真的希望Update-SPSolution了,讓你升級所有的活動功能的標誌。我還沒有遇到需要更新功能但不希望程序升級適用的情況。因此,剩下的PowerShell代碼通過遍歷所有網站集,爲我找到了需要根據預定義列表進行升級的所有功能,然後在顯示發生的任何錯誤的同時升級每個網站上的功能。

請注意,Update-SPSolution只刷新現有的文件。如果您已將新文件添加到解決方案包中,則它們將被忽略並不會被部署。我希望某個功能的版本歷史記錄和升級能力不會因收回/部署而無效,但我從未嘗試過。通常,如果我需要添加新文件,我將創建一個新的解決方案包。

相關問題