转载 SharePoint开发部署WSP解决方案包

转载原出处: http://642197992.blog.51cto.com/319331/1582731

注:本文所讲内容以SharePoint2013版本为例,开发工具以VS2013为基础。历史版本也可以参考本文。

WSP:SharePoint Solution Package 解决方案包。

 

一、概念和工具

    我们先引出WSP的由来。要想深入了解WSP,要先从SharePoint开发说起。SharePoint可开发的内容比较杂,最新版本的VS2013中已经包含了Sharepoint解决方案的基本模板,从创建到部署整个过程简单易用,比起以前开发解决方案要容易多了。但还是不能脱离SharePoint宿主机环境,不能远程开发和部署。不过SharePoint已经开始了新的编程思路就是SharePoint APP开发,这种开发模式已经可以在客户端编程部署了。

    工程师创建好SharePoint解决方案后,对列表库、Web部件、事件、网站模板、工作流等多方面进行编程开发。这一个个的功能就是Feature,那么如何最终把这些功能部署到SharePoint环境中呢,这就需要先把解决方案打包成WSP文件,其实这个WSP文件就是一个cab文件,是个压缩文件,你如果感兴趣可以用rar工具打开这个文件看看。

    要想打包解决方案为wsp文件,有很多种方法,以前我用过的方法有

  •  

    • WSPBuilder工具命令方式,相关链接CodePlex项目

    • WSPBuilderExtension,一个VS插件,这个比上面的方式更简单

    • SharePoint Software Factory(SP|SF),这是一个Visual Studio扩展工具,最新版本已经支持了VS2013版本,相关链接VS扩展CodePlex项目地址

    • 当然VS2013开发SharePoint解决方案已经可以从上下文菜单中直接部署了。在部署过程中会自动打包解决方案。

    • 当然一些其他第三方的cab生成工具也能帮助我们生成wsp文件,但操作过程还是繁琐复杂一些。

这些工具的使用不是本文所要讲解的部分,如何使用可关注我的博客的其他相关文章吧。

 

 

二、WSP部署、更新、删除

先要说明一下:

    解决方案分为:增加、安装(又名部署)、更新、收回、删除,

    Feature分为:激活、停用

增加解决方案

STSADM和SharePoint PowerShell两种命令,从SharePoint2013开始推荐用PowerShell命令集

STSADM命令示例如下(淘汰的用法):

>stsadm -o addsolution -filename <path>\YourSolution.wsp

PowerShell命令示例如下:

>Add-SPSolution -LiteralPath "wsp路径\文件名.wsp"

对于增加后的解决方案,可到管理中心部署解决方案:

>进入管理中心--系统设置--管理场解决方案,我在这里只引入功能所在位置,不去描述如何具体操作了。操作也很简单,也容易理解。

安装(部署)解决方案

>Install-SPSolution -Identity "YourSolution.wsp" -WebApplication "站点地址" -GACDeployment

更新解决方案

>Update-SPSolution -Identity "YourSolution.wsp" -LiteralPath "<path>\YourSolution.wsp" -GACDeployment -force

收回解决方案

>Uninstall-SPSolution -Identity "YourSolution.wsp"

删除解决方案

>Remove-SPSolution  -Identity "YourSolution.wsp"

注意:删除解决方案前,先要收回解决方案。

获取已增加的解决方案

>Get-SPSolution

解除解决方案的部署锁定

>Remove-SPSolutionDeploymentLock

三、Feature的部署、停用

在一个解决方案中,会包含一个及其以上的Feature,解决方案部署到站点后,可通过命令来控制解决方案中的各个Feature的状态。Feature概念可对应SharePoint解决方案项目中的Features目录里的结构定义。

获得Feature

>Get-SPFeature

上面这个命令可获得farm中的所有Feature,显示“名称、GUID、SharePoint功能版本”

>Get-SPFeature -Identity "<GUID>"

可以获得一个ID是GUID的那个Feature,

安装SharePoint功能

>Install-SPFeature -path "<YourSolution>_<FeatureName>"

卸载Feature

>Uninstall-SPFeature -Identity "<YourSolution>_<FeatureName>"

在给定范围启用Feature

>Enable-SPFeature -Identity "<YourSolution>_<FeatureName>" -URL "<siteUrl>"

在给定范围禁用Feature

>Disable-SPFeature -Identity "<YourSolution>_<FeatureName>" -URL "<siteUrl>"

四、沙箱解决方案

>Update-SPUserSolution

>Install-SPUserSolution

>Uninstall-SPUserSolution

>Remove-SPUserSolution

>Get-SPUserSolution

>Add-SPUserSolution

五、定时器解决方案

安装  AutoSenArvatodMailJob.wsp

 1)   Add-SPSolution -LiteralPath "c:\AutoSendMailJob.wsp"
 2)   Install-SPSolution -Identity "AutoSendMailJob.wsp" -WebApplication <siteUrl>  -GACDeployment
 3)   iisreset

4) Disable-SPFeature -Identity "AutoSendMailJob_Feature2" -Url "<siteUrl>" 5)   Enable-SPFeature -Identity "AutoSendMailJob_Feature2" -Url "<siteUrl>" 
 6)  net stop SPTimerV4 
 7)   net start SPTimerV4

 更新 AutoSenArvatodMailJob.wsp

1) Disable-SPFeature -Identity "Arvato.BBA.AutoSendMailJob_Feature2" -Url "<siteUrl>"

2) Uninstall-SPSolution –Identity "Arvato.BBA.AutoSendMailJob.wsp" -WebApplication "<siteUrl>" -Confirm:$false  
3) Remove-SPSolution –Identity Arvato.BBA.AutoSendMailJob.wsp -Confirm:$false
4) Add-SPSolution -LiteralPath "c:\Arvato.BBA.AutoSendMailJob2.wsp"
5) Install-SPSolution -Identity "Arvato.BBA.AutoSendMailJob.wsp" -WebApplication "<siteUrl>"  -GACDeployment
6) iisreset
7) Enable-SPFeature -Identity "Arvato.BBA.AutoSendMailJob_Feature2" -Url "<siteUrl>" 8
8) net stop SPTimerV4 
9) net start SPTimerV4

3、删除多余定时器方法

//查看 计时器 "ArvatoBBASendMailTimerJob"
Get-SPTimerJob | ?{$_.Name -match "ArvatoBBASendMailTimerJob"} |ft id,name 
//Set job to a variable
 $job = Get-SPTimerJob -id 59af3540-7ac0-4477-82f9-1f6ab9829aca 
//And delete it.
 $job.Delete()

 

最后说明一下:VS2013的SharePoint解决方案的bin\debug目录下,编译后会自动打包wsp文件。要想将方案远程部署到企业环境,可拷贝这个wsp文件,写好一个ps1的PowerShell脚本文件。交付给企业系统管理员执行安装就可以。

PS1脚本文件,可以被C#调用执行,这部分的讲解待后续博文摘写,在此说明一下。

以编写备份网站集PS1文件为例:

1
2
Add-PSSnapin  Microsoft.SharePoint.PowerShell 
backup-spsite -identity  $args [0] -path  $args [1] -force

该脚本用了backup-spsite来备份SharePoint网站集,并将网站的URL和备份路径设成两个参数,将其保存成后缀名为ps1的文件,比如backup.ps1

写一个批处理脚本,用于执行备份和写入日志。

1
2
3
4
5
6
7
8
@echo off
SET SOURCE_SITE=
SET DEST=C:\backup\RZH-SP-204_%date:~0,10%.bak
SET LOG=C:\backup\BackupLog.txt
echo %DATE%  %time:~,5%  :开始备份网站:%SOURCE_SITE%>> %LOG%
powershell -command C:\backup.ps1  %SOURCE_SITE% %DEST%
echo %DATE%  %time:~,5%  :网站:%SOURCE_SITE%备份完成>> %LOG%
@echo on

将这个脚本保存成bat批处理文件

不知道大家能否看懂以上代码,在这里我就不说明了。

最后奉献给大家一个完整的安装wsp解决方案的脚本,如果写的还不够完整,请大家告知!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Add-PSSnapin  Microsoft.SharePoint.PowerShell
$solutionName  "SharePointProject2.wsp"
$webUrl  "http://wisdom-moss/"
$path  Split-Path  -Parent  $MyInvocation .MyCommand.Definition
$solution  Get-SPSolution  | select name
foreach ( $s  in  $solution ){
     if ( $s  -match  $solutionName ){
         Write-Host  -ForegroundColor Green  "Solution '$solutionName' was existed."        
         $deployed  Get-SPSolution  -Identity  $solutionName  | select deployed
         if ( $deployed .Deployed){
             Write-Host  -ForegroundColor Green  "Start uninstall solution..."
             Uninstall-SPSolution -Identity  $solutionName  -Confirm: $false  -Verbose -WebApplication  $webUrl
             #sleep 30s, need uninstall over.
             Start-Sleep  -s 30
             Write-Host  -ForegroundColor Green  "End uninstall solution!"
         }
         Write-Host  -ForegroundColor Green  "Start remove solution..."
         Remove-SPSolution  -Identity  $solutionName  -Confirm: $false
         Write-Host  -ForegroundColor Green  "End remove solution!"
     }
}
Write-Host  -ForegroundColor Green  "Start add solution..."
Add-SPSolution  -LiteralPath ( $path  '\'  +   $solutionName )
Write-Host  -ForegroundColor Green  "End add solution!"
Write-Host  -ForegroundColor Green  "Start deploy solution..."
Install-SPSolution -Identity  $solutionName  -WebApplication  $webUrl  -FullTrustBinDeployment
Write-Host  -ForegroundColor Green  "End deploy solution!"
Write-Host  -ForegroundColor Green  "End all executed."

注释:因为我的解决方案被定义为程序集部署目标到WebApplication,所以dll我希望部署到网站集的bin目录下,如果您的解决方案希望部署到GAC,以用于将方案部署的全局,则需要将程序集部署目标到GlobalAssemblyCache。

 

转载于:https://www.cnblogs.com/wphl-27/p/5260647.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值