如何为 SharePoint 2010 Visual Studio 解决方案设置持续部署?

发布于 2024-09-25 23:52:37 字数 2981 浏览 2 评论 0原文

我想自动构建 .wsp 包并在每次提交后将它们重新部署到临时服务器上。我知道如何设置 CruiseControl.Net 进行持续集成,但我不知道如何构建和部署包。到目前为止,我已经 MSBuild 生成 .wsp 文件 ,但我正在努力处理自动重新部署脚本。到目前为止,我得到的是一个 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?

I want to automatically build .wsp packages and re-deploy them on a staging server after each commit. I know how to setup CruiseControl.Net for continuous integration, but I don't know how to build and deploy the packages. So far I got MSBuild to generate .wsp files , but I am struggling with a automatic re-deployment script. What I got so far is a PowerShell script:

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

This breaks with seemingly random errors, while the deployment from Visual Studio 2010 works every time. How can I deploy the .wsp's from command line in a fail-proof way like the Visual Studio does it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

可爱咩 2024-10-02 23:52:37

为什么不只使用 Update-SPSolution 而不是撤消-删除-安装-部署序列?

Why don't you just use Update-SPSolution instead of retract-delete-install-deploy sequence?

迷乱花海 2024-10-02 23:52:37

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

First of all, why are you over-complicating the deployment process by using PowerShell instead of stsadm in a batch file? Is there a need for PowerShell?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文