欧非资源网:安全、免费、专业放心的资源下载站! 最新软件|软件分类

您的位置:欧非资源网 > 其他专区 > SharePoint > Sharepoint 如何使用PowerShell添加和部署Solution

Sharepoint 如何使用PowerShell添加和部署Solution

时间:2020-01-15 21:56作者:admin来源:未知人气:286我要评论(0)

我们通常使用Visual Studio 2010来快速开发和部署我们的Sharepoint Solution.但有时我们不得不遇到要把我们开发的Solution Packages部署到其它物理位置(生产机),而不是我们开发环境所指向的服务器(测试机)。以前我们使用Stsadm工具来完成此工作,但现在我们更推荐使用PowerShell来操作。
     下面我们分别描述此工作涉及到的基本步骤:
一、添加Solution 到Sharepoint Farm中
通过我们要先将Visual Studio中的的Solution打包,打成的包可以到Solution的BinDebug目录下去找。把此目录下的Solution Package拷贝到需要部署的服务器上的指定目录下eg:  D:Sp2010DeploySolutionMySharepointProject.wsp
   如果用以前的Stsadm完成添加Solution工作则是 

   如果要使用PowerShell,则只需要从你的目标服务器桌面的的Start菜单中找到

 

    系统会自动加载Microsoft.SharePoint.PowerShell,我们便可以直接在其Command窗口中执行我们将要执行的PowerShell命令.如果对某个PowerShell命令(如Add-SPSolution)有使用上的问题,可在其Command窗口中使用Get-Help  Add-SPSolution 来取得此命令的相关帮助。
   此处,我们用PowerShell命令来完成添加Solution的工作:

Add-SPSolution  D:Sp2010DeploySolutionMySharepointProject.wsp

   如果你是开发的Sandboxed solution,那么你需要使用Add-SPUserSolution命令来执行上面的操作。此命令需要参数–literalpath,此参数提指向Solution的全路径,
二、部署Solution到指定的Web Application上
  接下来我们要部署Solution到我们指定的Web Application(eg: http://myserver-sp1:2010/)上
  如果用以前的Stsadm完成部署Solution工作则是

stsadm –o deploysolution –name MySharepointProject.wsp –url http://myserver-sp1:2010/    –allowCasPolicies –immediate

  如果是使用PowerShell命令,则如下

Install-SPSolution –Identity MySharepointProject.wsp –WebApplication http://myserver-sp1:2010/  -GACDeployment

  如果部署的是 Sandboxed solution,则使用Install-SPUserSolution命令。
    –GACDeployment 参数也可换成–CASPolicies,二者区别是
          GACDeployment指定可以为新 SharePoint 解决方案部署全局程序集缓存 (GAC)。。
           CASPolicies指定可以为新 SharePoint 解决方案部署代码访问安全 (CAS) 策略。
     - WebApplication参数也可换成- AllWebApplications,二者区别是:
         WebApplication: 为指定 SharePoint Web 应用程序部署 SharePoint 解决方案。该类型必须是格式为 12345678-90ab-cdef-1234-567890bcdefgh 的有效 GUID;

                                SharePoint Web 应用程序的有效名称(例如,MyOfficeApp1);或有效 SPWebApplication 对象的实例。

         AllWebApplications: 指定为服务器场中的所有 SharePoint Web 应用程序部署新的 SharePoint 解决方案。

  如果你需要强制部署此Solution,你可以使用-Force参数。
  通过上面两个步骤,你就完成了把指定的Sharepoint Solution Package添加和部署到指定的Sharepoint Farm和Web Application中。为使此文更完成,我们继续讨论我们可能要做的其它相关工作。
三、升级部署Solution.
我们可能要通过升级方式来部署我们已经在前面部署好的Solution,使用此方式前,我们首先需要把新版本的Solution拷贝到我们指定的目录下eg: D:Sp2010DeploySolutionMySharepointProject.wsp
   如果是使用Stsadm命令:

stsadm –o upgradesolution –name MySharepointProject.wsp –filename D:Sp2010DeploySolutionMySharepointProject.wsp –immediate –allowCasPolicies

  如果是使用PowerShell命令:

Update-SPSolution –Identity MySharepointProject.wsp –LiteralPath D:Sp2010DeploySolutionMySharepointProject.wsp  –GACDeployment

四、回收已经部署的Solution
  前面,我们已经完成了Instll, Deploy, Upgrade操作,接下来我们要实现Uninstall操作,此操作实现把Solution从指定的(或全部)WebApplication中回收回来。Solution仍然存在于Farm中,只是不再分配给WebApplication使用。
   使用PowerShell命令:

Uninstall-SPSolution –Identity MySharepointProject.wsp –WebApplication http://myserver-sp1:2010/

我们也可使用–AllWebApplications参数来一次性从此Sharepoint Farm中的所有部署此Solution的Web Application中回收Solution.
执行此命令时,系统会提示: . “Are you sure?” ,你只需要确定即可执行操作。

五、移除Solution
  这是最后一步,执行此步我们将从Sharepoint Farm中移除我们安装好的Solution.
  使用PowerShell命令:

Remove-SPSolution –Identity MySharepointProject.wsp

  上面的第四、五步如果用Stsadm来完成,则通常我们可以建立一个批处理文件eg: DeleteSolution.bat
代码内容如下(里面的内容要根据自身情况进行修改):

复制代码
:begin
@echo off
rem 
** declare the solution to be retracted **
set solutionName=SampleSolution
rem 
** declare the set of fetures to be de-activated **
set featureSampleFeature1=SampleFeature1
set featureSampleFeature2=SampleFeature2
set featureSampleFeature3=SampleFeature3
rem 
** Replace this value with the URL of your site **
@set url
=http://servername/sites/sitecollectioname/sitename
@set PATH=C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12BIN;%PATH% 
echo deactivating features 
in solution %solutionName%...
echo 
----------------------------------------------------
stsadm 
-o deactivatefeature -name %featureSampleFeature1% -url %url% -force
stsadm 
-o deactivatefeature -name %featureSampleFeature2% -url %url% -force
stsadm 
-o deactivatefeature -name %featureSampleFeature3% -url %url% -force
echo Attempting to uninstallfeature and retract solution
echo 
---------------------------------------------------
echo Rectracting solution 
%solutionName% from solution store...
stsadm 
-o retractsolution   -name %solutionName%.wsp -immediate
stsadm 
-o execadmsvcjobs 
echo Deleting solution 
%solutionName% from solution store...
stsadm 
-o deletesolution -name %solutionName%.wsp -override 
echo.
if errorlevel == 0 goto :success
:success
echo Successfully deployed solution and activated feature(s)..
echo .
goto end
:end
pause
复制代码

 stsadm –o addsolution –name D:Sp2010DeploySolutionMySharepointProject.wsp 

相关阅读 SharePoint中Office文件无法打开的解决方案如何快速生成SharePoint测试大文件如何查询SharePoint Library中空文件夹?如何快速备份SharePoint Farm Solution如何解决Event Viewer中SharePoint Error - Event ID 8321SharePoint 2016 CU安装失败,"Exception: The upgraded database schema doesn't match the TargetSchema"的解决方案InfoPath Error “此文档库已经被重命名或删除,或者网络问题导致文件无法保存…” 的解决方案SharePoint 2013 App概述How to Shrink SharePoint Content Database Log File?Project Web App Feature无法开启的解决方案

文章评论
发表评论

热门文章 SharePoint 2016 图文安装教程 后面有激活序列号、密钥分享[SharePoint入门教程]一SharePoint发展、工具及术语如何用 SharePoint Online创建团队网站?SharePoint Iframe 报错“此内容不能显示在一个框架中”

最新文章 SharePoint中Office文件无法打开的解决方案如何快速生成SharePoint测试大文件 如何查询SharePoint Library中空文件夹?如何快速备份SharePoint Farm Solution如何解决Event Viewer中SharePoint Error - Event ID 8321SharePoint 2016 CU安装失败,"Exception: The upgraded database s

人气排行 SharePoint 2016 图文安装教程 后面有激活序列号、密钥分享[SharePoint入门教程]一SharePoint发展、工具及术语如何用 SharePoint Online创建团队网站?SharePoint Iframe 报错“此内容不能显示在一个框架中”SharePoint 2013 安装图解 SharePoint安装步骤图解教程SharePoint 如何开启访问请求[SharePoint入门教程]一SharePoint概述[SharePoint入门教程]一创建SharePoint母版页

盖楼回复X

(您的评论需要经过审核才能显示)