3

我想自動生成的.wsp包和他們一個臨時服務器上重新部署每次提交後。我知道如何安裝CruiseControl.Net持續集成,但我不知道如何構建和部署軟件包。到目前爲止,我得到了MSBuild to generate .wsp files,但我用自動重新部署腳本掙扎。我走到這一步,是一個PowerShell腳本:我如何建立持續部署了SharePoint 2010的Visual Studio解決方案?

param([string]$siteUrl = "http://machine.local") 
$ErrorActionPreference = "Stop" 

function WaitForPendingJob 
{param ($sol) 
    $counter = 1 
    $sleeptime = 2 
    $safeguard = 100 
    while($sol.JobExists -and ($counter -lt $safeguard)) { 
     Write-Host -f yellow -NoNewLine "." 
     sleep $sleeptime 
     $counter++ 
    } 
    Write-Host "" 
} 

function InstallOrUpdateSolution 
{param ($SolutionWsp, $SiteUrl, $featureGuid) 
    $FullPath = resolve-path $SolutionWsp 
    $farm = Get-SPFarm 
    $sol = $farm.Solutions[$solutionWsp] 
    if ($sol) 
    { 
     Write-Host -f Green "Going to uninstall $SolutionWsp" 
     if($sol.Deployed -eq $TRUE) 
     { 
      Write-Host -f Green "Deactivating feature $featureGuid at $SiteUrl" 
      Disable-SPFeature -Identity $featureGuid -Url $SiteUrl -Confirm:$false -force -ErrorAction Continue 
      Uninstall-SPSolution -Identity $SolutionWsp -WebApplication $SiteUrl -Confirm:$false -ErrorAction Continue 
      Write-Host -f yellow -NoNewLine "waiting for retraction" 
      WaitForPendingJob $sol 

     } 
     Write-Host -f Green "$SolutionWsp is retracted." 
     Write-Host -f Green "Going to Remove $SolutionWsp" 
     Remove-SPSolution -Identity $SolutionWsp -Force -Confirm:$false -ErrorAction Continue 
     Write-Host -f Green $SolutionWsp is deleted from this Farm 
    } 

    Add-SPSolution -LiteralPath $FullPath 
    Install-SPSolution -Identity $SolutionWsp -WebApplication $SiteUrl -GACDeployment -CASPolicies -Force 
    $sol = $farm.Solutions[$SolutionWsp] 
    if ($sol.Deployed -eq $false) { 
     write-host -f yellow -NoNewLine "waiting for deployment" 
     WaitForPendingJob $sol 
    } 
    Write-Host -f Green $SolutionWsp deployed $sol.Deployed 
    Write-Host -f Green "Activating feature $SolutionWsp at $SiteUrl" 
    Enable-SPFeature -Identity $featureGuid -Url $SiteUrl 
} 

function RestartTimer 
{ 
    Write-Host -f Green Restarting OWSTIMER instances on Farm 
    $farm = Get-SPFarm 
    $farm.TimerService.Instances | foreach {$_.Stop();$_.Start();} 
} 

$date = Get-Date 
Write-Host -f Green "Starting upgrade at " $date 

Add-PsSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue 
InstallOrUpdateSolution "Solution1.wsp" $siteUrl "2c6ffaf7-84df-465c-be55-8136926d3e02" 
InstallOrUpdateSolution "Solution2.wsp" $siteUrl "0c6be7af-cccd-4ccd-9b61-deffd16f7830" 
InstallOrUpdateSolution "Solution3.wsp" $siteUrl "8f4862d3-94ea-467b-bdeb-2352295e08c3" 
RestartTimer 

$date = Get-Date 
Write-Host -f Green "Upgrade finished at" $date 

這打破了看似隨意的錯誤,而從Visual Studio 2010的部署屢試不爽。我怎樣才能像命令行一樣以Visual Studio的方式部署.wsp?

回答

-1

首先,爲什麼你是過於複雜的批處理文件中使用,而不是STSADM PowerShell中的部署過程?是否需要PowerShell?

+0

這不是話題,我知道如何安裝CI,這是我有問題,部署的一部分。 – skolima 2010-10-20 12:55:40

1

爲什麼不使用Update-SPSolution而不是retract-delete-install-deploy sequence?

+0

從MSDN:「Update-SPSolution cmdlet升級服務器場中已部署的SharePoint解決方案。僅當新解決方案包含與部署的解決方案相同的一組文件和功能時才使用此cmdlet。如果文件和功能不同,解決方案必須通過分別使用Uninstall-SPSolution和Install-SPSolution cmdlet撤銷和重新部署。「如果我添加一些資源文件,恐怕這會失敗。 – skolima 2010-12-14 07:08:33

+0

它不會失敗,要將資源(不在佈局文件夾中)實際部署到使用該功能的站點,您只需要停用並重新激活該功能 – Colin 2011-01-14 10:59:01

相關問題