【问题标题】:How can I set up continuous deployment for a SharePoint 2010 Visual Studio solution?如何为 SharePoint 2010 Visual Studio 解决方案设置持续部署?
【发布时间】:2010-12-14 05:44:45
【问题描述】:

我想在每次提交后自动构建 .wsp 包并在登台服务器上重新部署它们。我知道如何设置 CruiseControl.Net 以进行持续集成,但我不知道如何构建和部署包。到目前为止,我得到了 MSBuild to generate .wsp files ,但我正在努力使用自动重新部署脚本。到目前为止,我得到的是一个 PowerShell 脚本:

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?

【问题讨论】:

    标签: visual-studio-2010 continuous-integration sharepoint-2010 wsp


    【解决方案1】:

    为什么不直接使用 Update-SPSolution 而不是retract-delete-install-deploy 序列?

    【讨论】:

    • 来自 MSDN:“Update-SPSolution cmdlet 升级场中部署的 SharePoint 解决方案。仅当新解决方案包含与部署的解决方案相同的文件和功能集时,才使用此 cmdlet。如果文件和功能不同,必须分别使用 Uninstall-SPSolution 和 Install-SPSolution cmdlet 收回和重新部署解决方案。”如果我添加一些资源文件,恐怕这会失败。
    • 使用该功能将资源(不在布局文件夹中)实际部署到站点不会失败,您只需停用并重新激活该功能
    【解决方案2】:

    首先,您为什么在批处理文件中使用 PowerShell 而不是 stsadm 使部署过程过于复杂?是否需要 PowerShell?

    【讨论】:

    • 这不是主题,我知道如何设置 CI,这是我遇到问题的部署部分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多