我如何建立持续部署了SharePoint 2010的Visual Studio解决方案?

问题描述:

我想自动生成的.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?

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

+0

这不是话题,我知道如何安装CI,这是我有问题,部署的一部分。 – skolima 2010-10-20 12:55:40

为什么不使用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