转载原出处: 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。

转载 SharePoint开发部署WSP解决方案包的更多相关文章

  1. 不直接登录SharePoint服务器,通过远程直接部署WSP解决方案包

    在这之前不得不说一下Sysinternals,他最初是一个网站,网站上会经常发布一些有用的系统扩展工具,之后运营这个网站的公司被微软收购.像非常著名的Procmon,AutoRuns.Process ...

  2. SharePoint 2010 部署 WSP 包

    转:http://www.cnblogs.com/myheaven/archive/2011/05/19/2051180.html .net在工程的下面生成了WSP包,在Debug下面.需要放到生产环 ...

  3. 部署解决方案包 (SharePoint Server 2010)

    转:http://technet.microsoft.com/zh-cn/library/cc262995(v=office.14).aspx 本文介绍各个解决方案包,及其在 Microsoft Sh ...

  4. SharePoint 2010 使用Install-SPSolution部署wsp包状态一直是”正在部署”

    1.服务器场信息如下: 2.使用下面命令部署,状态一直是"正在部署" Install-SPSolution –Identity xxxx.wsp –WebApplication h ...

  5. SharePoint 2010 PowerShell 系列 之 备份、还原、部署 .WSP

    转:http://www.cnblogs.com/Fengger/archive/2012/08/24/2654093.html PowerShell系列目录 最近在部署测试环境,就顺便把PowerS ...

  6. NX11.0和VS2013 创建NXOpen 开发模版失败解决方案【转载】

    转载自PLM之家论坛 NX11.0和VS2013 创建NXOpen 开发模版失败解决方案 首先我觉得这个可能是西门子疏忽,基本上每个大版本没有补丁前都有类似问题,下面来说说怎么解决吧.注意这里版本,N ...

  7. SharePoint开发

    做SharePoint开发有时候是一件比较痛苦的事情,毕竟庞大的框架总是笨重的~~ 往往如果采取传统的方式开发SharePoint的话,更改一个代码需要有以下操作: 1)更改代码 2)VS编译——&g ...

  8. SharePoint 2013 本地创建解决方案

    在之前的博客<SharePoint 2013本地开发解决方案以及远程调试>中,我们介绍了如何通过修改注册表,使SharePoint 2013 解决方案可以本地编辑,也提及了即使修改注册表, ...

  9. PowerShell命令部署WSP

    转载:http://www.cnblogs.com/ChunLiangZhang/archive/2012/07/18/2597335.html(作者:ChunLiang) 现在可以用SharePoi ...

随机推荐

  1. Java泛型:类型擦除

    类型擦除 代码片段一 Class c1 = new ArrayList<Integer>().getClass(); Class c2 = new ArrayList<String& ...

  2. 123. Best Time to Buy and Sell Stock III

    题目: Say you have an array for which the ith element is the price of a given stock on day i. Design a ...

  3. P94、面试题12:打印1到最大的n位数

    题目:输入数字n,按顺序打印出从1最大的n位十进制数.比如输入3,则打印出1,2,3一直到最大的3位数999. 思路:先把字符串中的每一个数字都初始化为‘0’,然后每一次为字符串表示的数字加1,再打印 ...

  4. 高难度(1)什么是AR

    在介绍增强现实(AR)之前,需要先说说虚拟现实(VR) 虚拟现实是从英文Virtual Reality 一词翻译过来的,简称VR.VR 技术是采用以计算机技术为核心的技术,生成逼真的视.听.触觉等一体 ...

  5. GPS(1)核心API及3种列出LocationProvider的方法

    GPS的常用API Android SDK为GPS提供了很多API,其中LocationManager类是这些API的核心.所有与GPS相关的操作都由LocationManager对象及其派生的对象完 ...

  6. window.addEventListener来解决让一个js事件执行多个函数

    可能你也碰到过这种情况,就是在js的代码中用了window.onload后,可能会影响到body中的onload事件.这时就要用window.attachEvent和window.addEventLi ...

  7. WINCE6.0远程桌面显示修改

    备注:用RDP表示远程桌面 WINCE6.0自带的远程桌面在我们显示屏分辨率为240*320上有一部分内容无法显示出来,所以就需要调整界面让这些内容可见. 1.      PB6.0不支持对远程桌面资 ...

  8. Ubuntu设置中文

    Ubuntu设置中文:需要联网下载中文包,不然无法设置中文系统. 进去系统后再右上角有个齿轮图标点击,找到系统设置(System Settings)点击弹出一个界面,找到Language Suppor ...

  9. 序列化框架性能对比(kryo、hessian、java、protostuff)

    简介:   优点 缺点 Kryo 速度快,序列化后体积小 跨语言支持较复杂 Hessian 默认支持跨语言 较慢 Protostuff 速度快,基于protobuf 需静态编译 Protostuff- ...

  10. 《深入Java虚拟机学习笔记》- 第6章 class文件

    一.class文件内容 Java class文件是对Java程序二进制文件格式的精确定义.每一个Java class文件都对一个Java类或者Java接口作出了全面描述.一个class文件只 能包含一 ...