如何生成WebPart的部署文件(wsp文件)
使用VS2008進行WebPart開發(fā)時,用其自帶的部署菜單項進行部署時,總是有各種各樣的錯誤,最終無法生成部署文件和部署批處理文件。所以我一直想搞清楚VS2008是如何生成這些部署文件的。現(xiàn)在終于有了一個結(jié)果,可以與大家分享。
要生成部署文件需要以下幾個文件。
Defines the list of features, site definitions, resource files, web part files, and assemblies to be included in the Solution package
Manifest.xml文件通常作為Solution的入口點,用來指明在這個Solution中需要去處理的Package—你可以在FeatureManifests節(jié)點下指定多個FeatureManifest來執(zhí)行多個Feature的部署。在英文解釋中提到還可以指定別的一些類型的文件,但Assemblies是通常會在這里指定,其他文件最好被聲明在各個Feature中。
Defines the feature and specifies the location of assemblies, files, dependencies, or properties that support the Feature.
Feature.xml是很常見的配置文件,用來指定所安裝的Feature中要包含的DLL,以及其詳細配置文件Elements.xml的路徑。Feature.xml我們可以認為是單個Feature的入口點,大多數(shù)時間之需要指明Elements.xml的路徑,而無需將具體操作置入Feature.xml。這樣做是為了讓我們的配置文件更結(jié)構(gòu)化,功能化。
Element manifest file containing definitions to the feature's elements.
Elements.xml文件是最終這個Feature所要做的動作的具體描述。在這里可以應用諸如CustomAction, Module, ModuleGroup, Assemblies, ActivationDependencies, Recievers等擴展標記來告訴Package在部署時要做的動作。
Web Parts control description files contain property values, state data, and assembly or source file details exported from a WebPart control (or other ASP.NET server or user control used in a Web Parts application) to an XML file with a .WebPart extension.
.webpart文件包含了Webpart的屬性、數(shù)據(jù)等信息。
Package.ddf is a MakeCab diamond directive file used to define the structure and contents of the solution package.
.ddf文件指定了將來生成的.CAB文件或.WSP文件包含的內(nèi)容。這里定義了所有需要部署的文件結(jié)構(gòu)信息。需要注意的是,目錄結(jié)構(gòu)的變化需要用.SET DESTINATIONDIR=’’ 來顯式指定。
??????? (注:以上部分說明引自博客:初探SharePoint部署 – WSS Solution Package )
?
?以下是各個文件的具體實例:
Code
<?xml?version="1.0"?encoding="utf-8"?>
<Solution?SolutionId="42560968-69f5-4535-a1fc-9d3d2428eb4e"?xmlns="http://schemas.microsoft.com/sharepoint/">
??<FeatureManifests>
????<FeatureManifest?Location="MeetingSchedule\feature.xml"?/>
??</FeatureManifests>
??<Assemblies>
????<Assembly?Location="MeetingSchedule.dll"?DeploymentTarget="GlobalAssemblyCache">
??????<SafeControls>
????????<SafeControl?Assembly="MeetingSchedule,?Version=1.0.0.0,?Culture=neutral,?PublicKeyToken=9f4da00116c38ec5"?Namespace="MeetingSchedule"?TypeName="MeetingSchedule"?Safe="True"?/>
??????</SafeControls>
????</Assembly>
??</Assemblies>
</Solution>
Code
<?xml?version="1.0"?encoding="utf-8"?>
<Feature?Id="91a1e498-bd15-439c-b28f-bde8f690ef55"?Title="MeetingSchedule"?Scope="Site"?Version="1.0.0.0"?Hidden="FALSE"?DefaultResourceFile="core"?xmlns="http://schemas.microsoft.com/sharepoint/">
??<ElementManifests>
????<ElementManifest?Location="MeetingSchedule\MeetingSchedule.xml"?/>
????<ElementFile?Location="MeetingSchedule\MeetingSchedule.webpart"?/>
??</ElementManifests>
</Feature>
注意:此處的.webpart文件的名字為MeetingSchedule.webpart;ElementManifest文件的名字為MeetingSchedule.xml。
Code
<?xml?version="1.0"?encoding="utf-8"?>
<Elements?Id="02342748-2698-4e26-867a-9b4abd2b9da7"?xmlns="http://schemas.microsoft.com/sharepoint/">
??<Module?Name="WebParts"?List="113"?Url="_catalogs/wp">
????<File?Path="MeetingSchedule\MeetingSchedule.webpart"?Url="MeetingSchedule.webpart"?Type="GhostableInLibrary"?/>
??</Module>
</Elements>
Code
<?xml?version="1.0"?encoding="utf-8"?>
<webParts>
??<webPart?xmlns="http://schemas.microsoft.com/WebPart/v3">
????<metaData>
??????<!--
??????The?following?Guid?is?used?as?a?reference?to?the?web?part?class,?
??????and?it?will?be?automatically?replaced?with?actual?type?name?at?deployment?time.
??????-->
??????<type?name="MeetingSchedule.MeetingSchedule,?MeetingSchedule,?Version=1.0.0.0,?Culture=neutral,?PublicKeyToken=9f4da00116c38ec5"?/>
??????<importErrorMessage>Cannot?import?MeetingSchedule?Web?Part.</importErrorMessage>
????</metaData>
????<data>
??????<properties>
????????<property?name="Title"?type="string">MeetingSchedule?Web?Part</property>
????????<property?name="Description"?type="string">MeetingSchedule?Description</property>
??????</properties>
????</data>
??</webPart>
</webParts>
Code
;
.OPTION?EXPLICIT?????;?Generate?errors?
.Set?CabinetNameTemplate=MeetingSchedule.wsp?????
.set?DiskDirectoryTemplate=CDROM?;?All?cabinets?go?in?a?single?directory
.Set?CompressionType=MSZIP;**?All?files?are?compressed?in?cabinet?files
.Set?UniqueFiles="ON"
.Set?Cabinet=on
.Set?DiskDirectory1=Package
;adds?manifest?file
manifest.xml
;adds?webpart?dll
MeetingSchedule.dll
;sets?the?title?webpart?feature?directory
.Set?DestinationDir=MeetingSchedule
;adds?the?feature?manifest?to?the?feature?directory?
MeetingSchedule\feature.xml?feature.xml
;adds?the?webpart?manifest?to?the?feature?directory?
MeetingSchedule\MeetingSchedule\MeetingSchedule.webpart?MeetingSchedule\MeetingSchedule.webpart
;adds?the?element?manifest?to?the?feature?directory?
MeetingSchedule\MeetingSchedule\MeetingSchedule.xml?MeetingSchedule\MeetingSchedule.xml
這些文件的目錄結(jié)構(gòu)為:
\root
??? manifest.xml
??? MeetingSchedule.ddf
??? MeetingSchedule.ddl
??? \MeetingSchedule
??????? feature.xml
??????? \MeetingSchedule
??????????? MeetingSchedule.webpart
??????????? MeetingSchedule.xml
注:這其中的feature.xml、manifest.xml文件、.webpart文件和ElementManifest文件,都由VS2008自動生成。但是manifest.xml文件中不含有SafeControls的信息,需要自己添加。查看方法:選擇View->Other Windows->WSP View。除了ddf文件外,其他文件在VS2008能夠正常部署時也可以自動生成(包括正確的manifest.xml文件)。實際上我的這些文件就是這樣得到的。
好了,到此為止我們已準備好了所有文件,現(xiàn)在就可以開始生成部署文件了。生成的部署文件,實際上是由Makecab壓縮成的cab文件,只不過其后綴改為了wsp而已。在root下執(zhí)行:
????????Makecab /F?meetingschedule.ddf
就可以生成一個新的目錄Package,在此目錄下含有生成的部署文件:MeetingSchedule.wsp。
現(xiàn)在可以進行部署了。通常執(zhí)行Stsadm就可以進行部署,但是為了每次部署及解除部署的方面,最好使用一個批處理文件自動進行。VS2008在能夠正常部署時,會自動生成這樣一個名為“Setup.bat”批處理文件。我就把這個文件照搬到此,作為模板,以后可以根據(jù)需要改動。
注意:其中的Feature Id,就是Feature.xml中的ID。
@rem======================================================================
@rem
@rem????setup.bat
@rem
@rem======================================================================
@echo?off
setlocal
pushd?.
goto?LInitialize
@rem----------------------------------------------------------------------
@rem????LInitialize
@rem----------------------------------------------------------------------
:LInitialize
????set?SPAdminTool=%CommonProgramFiles%\Microsoft?Shared\web?server?extensions\12\BIN\stsadm.exe
????set?Install=
????set?Uninstall=
????set?PackageFile=%~dp0Package\MeetingSchedule.wsp
????set?PackageName=MeetingSchedule.wsp
????set?DefaultWebUrl=http://myserver:40000
????set?DefaultSiteUrl=http://myserver:40000
????set?TargetWebUrl=
????set?TargetSiteUrl=
????goto?LParseArgs
@rem----------------------------------------------------------------------
@rem????LParseArgs
@rem----------------------------------------------------------------------
:LParseArgs
????@rem?---?help?---
????if?"%1"?==?"/?"????goto?LHelp
????if?"%1"?==?"-?"????goto?LHelp
????if?"%1"?==?"/h"????goto?LHelp
????if?"%1"?==?"-h"????goto?LHelp
????if?"%1"?==?"/help"?goto?LHelp
????if?"%1"?==?"-help"?goto?LHelp
????@rem?---?Fix?execute?task?---
????if?"%1"?==?"/i"?????????(set?Install=1)???&?shift?&?goto?LParseArgs
????if?"%1"?==?"-i"?????????(set?Install=1)???&?shift?&?goto?LParseArgs
????if?"%1"?==?"/install"???(set?Install=1)???&?shift?&?goto?LParseArgs
????if?"%1"?==?"-install"???(set?Install=1)???&?shift?&?goto?LParseArgs
????if?"%1"?==?"/u"?????????(set?Uninstall=1)?&?shift?&?goto?LParseArgs
????if?"%1"?==?"-u"?????????(set?Uninstall=1)?&?shift?&?goto?LParseArgs
????if?"%1"?==?"/uninstall"?(set?Uninstall=1)?&?shift?&?goto?LParseArgs
????if?"%1"?==?"-uninstall"?(set?Uninstall=1)?&?shift?&?goto?LParseArgs
????
????@rem?---?Fix?url?---
????if?"%1"?==?"/weburl"??(set?TargetWebUrl=%2)??&?shift?&?shift?&?goto?LParseArgs
????if?"%1"?==?"-weburl"??(set?TargetWebUrl=%2)??&?shift?&?shift?&?goto?LParseArgs
????if?"%1"?==?"/siteurl"?(set?TargetSiteUrl=%2)?&?shift?&?shift?&?goto?LParseArgs
????if?"%1"?==?"-siteurl"?(set?TargetSiteUrl=%2)?&?shift?&?shift?&?goto?LParseArgs
????@rem?---?Check?invalid?arguments?---
????if?not?"%1"?==?""?(
????????echo?Invalid?argument.
????????goto?LHelp
????)
????@rem?---?Check?arguments?---
????if?"%Install%"?==?"1"?(
????????if?"%Uninstall%"?==?"1"?(
????????????goto?LHelp
????????)
????)
????if?"%Install%"?==?""?(
????????if?"%Uninstall%"?==?""?(
????????????set?Install=1
????????)
????)
????if?"%TargetSiteUrl%"?==?""?(
????????if?"%TargetWebUrl%"?==?""?(
????????????set?TargetWebUrl=%DefaultWebUrl%
????????????set?TargetSiteUrl=%DefaultSiteUrl%
????????)
????????if?not?"%TargetWebUrl%"?==?""?(
????????????set?TargetSiteUrl=%TargetWebUrl%
????????????echo?Setting?TargetSiteUrl?to?be?%TargetWebUrl%
????????)
????)
????if?"%TargetWebUrl%"?==?""?(
????????set?TargetWebUrl=%TargetSiteUrl%
????????echo?Setting?TargetWebUrl?to?be?%TargetSiteUrl%
????)
????goto?LMain
@rem----------------------------------------------------------------------
@rem????LHelp
@rem----------------------------------------------------------------------
:LHelp
????echo?Usage:
????echo?setup.bat?[/install?or?/uninstall][/weburl?^<url^>][/siteurl?^<url^>]
????echo???????????[/help]
????echo.
????echo?Options:
????echo??/install?or?/uninstall
????echo??Install?specified?Solution?package?(.wsp)?to?the?SharePoint?server
????echo??or?uninstall?specified?Solution?from?the?SharePoint?server.
????echo??Default?value:?install
????echo??/weburl
????echo??Specify?a?web?url?of?the?SharePoint?server.
????echo??Default?value:?%DefaultWebUrl%
????echo??/siteurl
????echo??Specify?a?site?url?of?the?SharePoint?server.
????echo??Default?value:?%DefaultSiteUrl%
????echo??/help
????echo??Show?this?information.
????echo.
????goto?LTerminate
@rem----------------------------------------------------------------------
@rem????LMain
@rem----------------------------------------------------------------------
:LMain
????if?"%Install%"?==?"1"?(
??????call?:LDeploy
??)
????if?"%Uninstall%"?==?"1"?(
??????call?:LRetract
??)
????goto?LTerminate
@rem----------------------------------------------------------------------
@rem????LDeploy
@rem----------------------------------------------------------------------
:LDeploy
????echo?Adding?solution?%PackageName%?to?the?SharePoint?
????"%SPAdminTool%"?-o?addsolution?-filename?"%PackageFile%"
????echo?Deploying?solution?%PackageName%?
????"%SPAdminTool%"?-o?deploysolution?-name?"%PackageName%"?-local?-allowGacDeployment?-url?%TargetWebUrl%
????echo?Activating?feature?YBDC.MeetingSchedule?
????"%SPAdminTool%"?-o?activatefeature?-id?91a1e498-bd15-439c-b28f-bde8f690ef55?-url?%TargetSiteUrl%
????goto?:EOF
@rem----------------------------------------------------------------------
@rem????LRetract
@rem----------------------------------------------------------------------
:LRetract
????echo?Deactivating?feature?YBDC.MeetingSchedule?
????"%SPAdminTool%"?-o?deactivatefeature?-id?91a1e498-bd15-439c-b28f-bde8f690ef55?-url?%TargetSiteUrl%
????echo?Uninstalling?feature?YBDC.MeetingSchedule?
????"%SPAdminTool%"?-o?uninstallfeature?-id?91a1e498-bd15-439c-b28f-bde8f690ef55?-force
????echo?Retracting?solution?%PackageName%?
????"%SPAdminTool%"?-o?retractsolution?-name?"%PackageName%"?-local?-url?%TargetWebUrl%
????echo?Deleting?solution?%PackageName%?from?SharePoint?
????"%SPAdminTool%"?-o?deletesolution?-name?"%PackageName%"
????goto?:EOF
@rem----------------------------------------------------------------------
@rem????LTerminate
@rem----------------------------------------------------------------------
:LTerminate
????set?UserInput=
????set?/P?UserInput=Hit?enter?key?to?quit.
????set?SPAdminTool=
????set?PackageFile=
????set?PackageName=
????set?Install=
????set?Uninstall=
????set?TargetSiteUrl=
????set?TargetWebUrl=
????set?UserInput=
popd
endlocal
這樣就可以方面的進行部署與解除。
部署命令:Setup /i
解除命令:Setup /u
?
轉(zhuǎn)載于:https://www.cnblogs.com/Wangyong-Wen/archive/2009/03/05/1402473.html
總結(jié)
以上是生活随笔為你收集整理的如何生成WebPart的部署文件(wsp文件)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于每年一次的社会保险缴费基数核定说明
- 下一篇: FMS3系列(二):创建可交互的FMS连