转载 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 offSET SOURCE_SITE=SET DEST=C:\backup\RZH-SP-204_%date:~0,10%.bakSET LOG=C:\backup\BackupLog.txtecho %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 nameforeach($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 -FullTrustBinDeploymentWrite-Host -ForegroundColor Green "End deploy solution!"Write-Host -ForegroundColor Green "End all executed." |
注释:因为我的解决方案被定义为程序集部署目标到WebApplication,所以dll我希望部署到网站集的bin目录下,如果您的解决方案希望部署到GAC,以用于将方案部署的全局,则需要将程序集部署目标到GlobalAssemblyCache。
转载 SharePoint开发部署WSP解决方案包的更多相关文章
- 不直接登录SharePoint服务器,通过远程直接部署WSP解决方案包
在这之前不得不说一下Sysinternals,他最初是一个网站,网站上会经常发布一些有用的系统扩展工具,之后运营这个网站的公司被微软收购.像非常著名的Procmon,AutoRuns.Process ...
- SharePoint 2010 部署 WSP 包
转:http://www.cnblogs.com/myheaven/archive/2011/05/19/2051180.html .net在工程的下面生成了WSP包,在Debug下面.需要放到生产环 ...
- 部署解决方案包 (SharePoint Server 2010)
转:http://technet.microsoft.com/zh-cn/library/cc262995(v=office.14).aspx 本文介绍各个解决方案包,及其在 Microsoft Sh ...
- SharePoint 2010 使用Install-SPSolution部署wsp包状态一直是”正在部署”
1.服务器场信息如下: 2.使用下面命令部署,状态一直是"正在部署" Install-SPSolution –Identity xxxx.wsp –WebApplication h ...
- SharePoint 2010 PowerShell 系列 之 备份、还原、部署 .WSP
转:http://www.cnblogs.com/Fengger/archive/2012/08/24/2654093.html PowerShell系列目录 最近在部署测试环境,就顺便把PowerS ...
- NX11.0和VS2013 创建NXOpen 开发模版失败解决方案【转载】
转载自PLM之家论坛 NX11.0和VS2013 创建NXOpen 开发模版失败解决方案 首先我觉得这个可能是西门子疏忽,基本上每个大版本没有补丁前都有类似问题,下面来说说怎么解决吧.注意这里版本,N ...
- SharePoint开发
做SharePoint开发有时候是一件比较痛苦的事情,毕竟庞大的框架总是笨重的~~ 往往如果采取传统的方式开发SharePoint的话,更改一个代码需要有以下操作: 1)更改代码 2)VS编译——&g ...
- SharePoint 2013 本地创建解决方案
在之前的博客<SharePoint 2013本地开发解决方案以及远程调试>中,我们介绍了如何通过修改注册表,使SharePoint 2013 解决方案可以本地编辑,也提及了即使修改注册表, ...
- PowerShell命令部署WSP
转载:http://www.cnblogs.com/ChunLiangZhang/archive/2012/07/18/2597335.html(作者:ChunLiang) 现在可以用SharePoi ...
随机推荐
- jquery layout学习
1.官网:http://layout.jquery-dev.com/index.cfm 2.博客园:http://www.cnblogs.com/chen-fan/articles/2044556.h ...
- 202. Happy Number
题目: Write an algorithm to determine if a number is "happy". A happy number is a number def ...
- 198. House Robber
题目: You are a professional robber planning to rob houses along a street. Each house has a certain am ...
- 91. Decode Ways
题目: A message containing letters from A-Z is being encoded to numbers using the following mapping: ' ...
- POJ2993——Help Me with the Game(字符串处理+排序)
Help Me with the Game DescriptionYour task is to read a picture of a chessboard position and print i ...
- 驱动之路-platform简例按键驱动☆☆☆
一 .重要知识点: ▉1.platform设备模型 从Linux 2.6起引入了一套新的驱动管理和注册机制,platform_device和platform_driver,Linux中大部分的设备驱动 ...
- 1471. Tree(LCA)
1471 先学习了下tarjan算法的LCA 离线算法 它是先知道询问的结点对 在遍历的时候就已经算出来了 看篇图解 讲的很清楚 #include <iostream> #include& ...
- 各种html5 的 polyfill
https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills 配合 Modernizr
- 8.20 usaco
summary:14 1.k短路 2.tarjan缩无向图点 3.复习了SA 4.差分约束 5.求第二短路 洛谷3824:dfs优化背包.开始的时候mle了,然后我就把a[i],w[i]去掉....就 ...
- apache开源项目--log4j
Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口服务 器.NT的事件记录器.UNIX Syslog守护进程等; ...