如何生成WebPart的部署文件(wsp文件)
使用VS2008进行WebPart开发时,用其自带的部署菜单项进行部署时,总是有各种各样的错误,最终无法生成部署文件和部署批处理文件。所以我一直想搞清楚VS2008是如何生成这些部署文件的。现在终于有了一个结果,可以与大家分享。
要生成部署文件需要以下几个文件。
- Manifest.xml
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节点下指定多个FeatureManifest来执行多个Feature的部署。在英文解释中提到还可以指定别的一些类型的文件,但Assemblies是通常会在这里指定,其他文件最好被声明在各个Feature中。 - Feature.xml
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的入口点,大多数时间之需要指明Elements.xml的路径,而无需将具体操作置入Feature.xml。这样做是为了让我们的配置文件更结构化,功能化。 - MyWebPartManifest.xml
Element manifest file containing definitions to the feature's elements.
Elements.xml文件是最终这个Feature所要做的动作的具体描述。在这里可以应用诸如CustomAction, Module, ModuleGroup, Assemblies, ActivationDependencies, Recievers等扩展标记来告诉Package在部署时要做的动作。 - MyWebpart.webpart
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的属性、数据等信息。 - MyWebpart.ddf
Package.ddf is a MakeCab diamond directive file used to define the structure and contents of the solution package.
.ddf文件指定了将来生成的.CAB文件或.WSP文件包含的内容。这里定义了所有需要部署的文件结构信息。需要注意的是,目录结构的变化需要用.SET DESTINATIONDIR=’’ 来显式指定。
(注:以上部分说明引自博客:初探SharePoint部署 – WSS Solution Package )
以下是各个文件的具体实例:
- Manifest.xml
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> - Feature.xml
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。
- MyWebPartManifest.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> - MyWebpart.webpart
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> - MyWebpart.ddf
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
这些文件的目录结构为:
\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文件)。实际上我的这些文件就是这样得到的。
好了,到此为止我们已准备好了所有文件,现在就可以开始生成部署文件了。生成的部署文件,实际上是由Makecab压缩成的cab文件,只不过其后缀改为了wsp而已。在root下执行:
Makecab /F meetingschedule.ddf
就可以生成一个新的目录Package,在此目录下含有生成的部署文件:MeetingSchedule.wsp。
现在可以进行部署了。通常执行Stsadm就可以进行部署,但是为了每次部署及解除部署的方面,最好使用一个批处理文件自动进行。VS2008在能够正常部署时,会自动生成这样一个名为“Setup.bat”批处理文件。我就把这个文件照搬到此,作为模板,以后可以根据需要改动。
注意:其中的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
转载于:https://www.cnblogs.com/Wangyong-Wen/archive/2009/03/05/1402473.html
如何生成WebPart的部署文件(wsp文件)相关推荐
- 使用WSPBuilder 生成wsp文件,部署,激活,使用
MSDN:http://social.msdn.microsoft.com/Forums/zh-CN/sharepointwebpartzhchs/thread/3b8ebd96-6fdf-4c25- ...
- java7找不到uri_部署-Java Jar文件:使用资源错误:URI不是hierarchi
部署-Java Jar文件:使用资源错误:URI不是hierarchi 我已将我的应用程序部署到jar文件. 当我需要将数据从一个资源文件复制到jar文件外部时,请执行以下代码: URL resour ...
- BIMServer1.5.88服务器部署及IFC文件上传并3D显示
BIMServer1.5.88服务器部署及IFC文件上传并3D显示 一.JDK安装与环境变量配置 1.JDK SE 8下载 2.JDK SE 8安装 3.JDK 环境配置 二.BIMServer1. ...
- Nginx部署前端dist文件夹
Nginx部署前端dist文件夹 nginx部署dist包_墨寒ice的博客-CSDN博客_nginx dist nginx服务器部署dist文件夹 - 菜鸟学院 (noobyard.com) ngi ...
- vue html引入资源dev下404,webpack vue 项目打包生成的文件,资源文件报404问题的修复方法(总结篇)...
最近在使用webpack + vue做个人娱乐项目时,发现npm run build后,css js img静态资源文件均找不到路径,报404错误...网上查找了一堆解决办法,总结如下 一.首先修改c ...
- ubuntu php xml模块,生成ubuntu自动切换壁纸xml文件的php代码
运行代码后在图片目录下会生成yuxing.xml,方便ubuntu自动切换壁纸. /* * 生成ubuntu自动切换壁纸xml文件 */ //图片目录 $dir = '/home/yuxing/bac ...
- R语言使用fs包的path_wd函数基于自定义文件路径规则,批量生成多个文件或者文件夹对应的绝对(absolute)文件路径(constructs absolute path)
R语言使用fs包的path_wd函数基于自定义文件路径规则,批量生成多个文件或者文件夹对应的绝对(absolute)文件路径(constructs an absolute path from the ...
- python使用fpdf生成pdf章节(chapter)文件包含:页眉、页脚、章节主体、章节内容等;
python使用fpdf生成pdf章节(chapter)文件包含:页眉.页脚.章节主体.章节内容等: 目录
- iOS安全之RSA加密/生成公钥、秘钥 pem文件
在iOS中使用RSA加密解密,需要用到.der和.p12后缀格式的文件,其中.der格式的文件存放的是公钥(Public key)用于加密,.p12格式的文件存放的是私钥(Private key)用于 ...
最新文章
- 叮!你有一份2018英特尔人工智能大会的邀请函,请查收!
- 【jquery版.net控件—dropdownlist】附源码,欢迎大家指点、指正、拍砖!!!
- 仿微信朋友圈项目梳理
- 用ASP.NET Core 2.1 建立规范的 REST API -- HATEOAS
- JAVA软件图片浏览下载_java模拟浏览器下载图片
- icoding复习1,2
- centos8安装并启动tomcat9
- 内置对象和内置函数_内置假对象
- mysql 8.0 重置数据库,Mysql 8.0安装及重置密码问题
- 大数据_Hbase-(概念补充_hbase中namespace的概念)---Hbase工作笔记0007
- android仿饿了么筛选,Android仿饿了么搜索功能
- 2010年的20款游戏
- WPF 3D:简单的Point3D和Vector3D动画创造一个旋转的正方体
- 第十三届“恩智浦”杯全国大学生智能汽车竞赛-信标对抗组比赛总结
- R和Rstudio安装教程
- OpenCv图像处理实战——银行卡卡号识别
- 圆锥曲线万能弦长公式_圆锥曲线的弦长公式及其推导过程
- Rust 闭包学习 (Fn/FnMut/FnOnce)
- 万物互联时代的兴起及其边缘算法效应
- 特权同学IP核心中的学习