Escolar Documentos
Profissional Documentos
Cultura Documentos
Best Practices
9/7/2009
Contents
Purpose of the Document:..........................................................................................3
Intended Audience:....................................................................................................3
Technology:................................................................................................................3
Reference Project Name:............................................................................................3
Contributors:..............................................................................................................3
Requirement Scenario:...............................................................................................3
Work Scope in the Project..........................................................................................3
Solution Identified and Provided:................................................................................4
Deploying Web Part / Feature as SharePoint Solution Package (.wsp file)..................4
12 Hive.......................................................................................................................4
Solution File................................................................................................................4
Manifest.xml file and how it relates to the WSP file....................................................5
Feature.xml................................................................................................................9
Generating the WSP using a DDF file.......................................................................10
Creating Build.cmd file.............................................................................................12
Creating Installation.bat file.....................................................................................13
SharePoint Deployment Graphical Representation...................................................14
Web Part Deployment Example................................................................................15
Where it can be used:...............................................................................................23
Is this the Work Around or Best Solution:.................................................................23
Document / Product / Component Repository Path:.................................................23
Document / Product / Component Repository Path:
2
Purpose of the Document:
This document is used to illustrate the Web Part deployment process using ddf file.
Intended Audience:
SharePoint Developer
Technology:
Microsoft SharePoint Server 2007
Contributors:
➢ Arun k Sahu
➢ Amol Sortey
➢ Mahesh Patil
Requirement Scenario:
Client wants the automation process to deploy the web part as feature using .ddf
file.
3
Solution Identified and Provided:
12 Hive
12 hive is where SharePoint files are installed. When we deploy a solution
package using the stsadm.exe command:
Typically, when you create a new MOSS /WSS project, you replicate the
directory structure of 12 hive in your project. The reason will become
apparent later when we create the solution. In addition, if you plan to use a
tool like wspbuilder, the tool expects you to organize the directory in the
same manner as 12 hive.
Solution File
Solution file has an extension “.wsp”. Solution file contains everything
needed to deploy your Web Part/ feature. Solution file is just a cab file, so we
can open it by changing the extension from “.wsp” to “.cab” and then
double-clicking on it.
Here’s an example of the content of a WSP file:
4
Manifest.xml
MyFeature\Feature.xml
ControlTemplates\MyFeatureForm.ascx
MyFeature.dll
Notice the Manifest.xml file at the beginning. A solution file may hold a
variety of different files, but it always has a manifest.xml file. This manifest
file list what is in the solutions file?
This manifest tells us that this WSP has an Assembly (.dll), a user control
(.ascx), and a feature.xml file. There may be additional files in WSP. You can
even embed a movie into the WSP. But unless the file is specified in the
manifest, the installer will skip over it during installation.
5
SharePoint. When you create a new package, you must always create a new
GUID. The other elements specify what is in the WSP file and where to find
them via the location attribute. The location does actually follow the 12 hive,
but the root location will change according to the element type.
The <Assembly> element specifies where the DLL is located. The root for
this element is the web application bin file if you specify
DeploymentTarget=”WebApplication”, and the GAC if you specify
DeploymentTarget=”GlobalAssemblyCache”. In the above example, the
<Assembly> element tells the installer to look in the root of the WSP file for
the MyFeature.dll and deploy it to the GAC, which is typically located in
C:\Windows\System32\Assembly on most systems.
6
Manifest Element Location’s Root
ApplicationResourceFile 12\Resources
FeatureManifest 12\TEMPLATE\FEATURES
ResourceFile 12\TEMPLATE\FEATURES
RootFile 12
SiteDefinationManifest 12\TEMPLATE\SiteTemplates
TemplateFile 12\TEMPLATE
WebTemplateFile 12\TEMPLATE
For example, you want to group your user controls (.ascx) under a folder
(12\TEMPLATE\CONTROLTEMPLATES\MyProject\), instead of deploying your user
control files to 12\TEMPLATE\CONTROLTEMPLATES\ you can change the location
from
<TemplateFile Location="ControlTemplates\MyFeatureForm.ascx"/>
To
<TemplateFile Location="ControlTemplates\MyProject\MyFeatureForm.asc
x"/>
Features are always limited to one layer deep. If you try to specify
location=”MyProject\MyFeature\feature.xml” for a FeatureManifest element,
you will get an error message that you cannot go beyond one level deep. In
additon, specifying location=”Myproject\MyFeature.dll” doesn’t make sense
either because you’ll end up with a subdirectory inside the GAC.
7
More Information
The solution element defines the solutionId, just a new GUID and the deployment
server type.
The FeatureManifests element refers to the feature.xml files collection. You can
deploy many features with one solution. Just specify the different Feature folders,
You must define one feature.xml file for each feature.
You cannot name “feature.xml” file as anything other than the feature.xml . Doing
so yield following error.
The Assemblies element defines which assembly you are deploying. For timer
jobs you must deploy to the GAC, however for other items, you can choose
WebApplication as the deployment target. If you deploy as a webapplication, you
must add an entry into the web.config file located in the root of the virtual directory
of the target of the deployment which specifies the file as “SafeControl” in the
SafeControls Element.
The “TemplateFiles“ element defines the location and files from your project needs
to fetched in order to copy to the 12 hive directory. You can define multiple files
from your project.
8
Feature.xml
<?xml version="1.0" encoding="utf-8"?>
<Feature Id="f98c395e-9ac0-4176-9323-11b5c0cba0ca" Title="MyFeature"
Scope="Site" Version="1.0.0.0" Hidden="FALSE" DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="MyFeature\feature.xml" />
<ElementFile Location="MyFeature\MyFeature.webpart" />
</ElementManifests>
</Feature>
ElementManifest: points to other files that are going to describe things that need
to be deployed with your feature.
9
Generating the WSP using a DDF file
A DDF is basically an instruction file for building WSP files. Let’s examine the
DDF file used to build the WSP example.
.OPTION EXPLICIT
; Specify the output filename
.Set CabinetNameTemplate="MyFeature.wsp"
; Specify where to create the WSP file
.Set DiskDirectoryTemplate="..\Deployment"
; Compress the solution package
.Set CompressionType=MSZIP
; You always have a manifest file
manifest.xml
; Assembly gets placed in the top level
bin\Release\MyFeature.dll
; Features placed in location specify in FeatureManifest
.Set DestinationDir="MyFeature"
12\TEMPLATE\FEATURES\MyFeature\feature.xml
; User control placed in location specified in TemplateFile
.SET DestinationDir="ControlTemplates"
12\TEMPLATE\ControlTemplates\MyFeatureForm.ascx
1. CabinetNameTemplate: Sepecifies what the output file name is
going to be.
3. The rest of the DDF handles the adding of files to the WSP archive. You
specify the file using a path relative to your project’s root. In the above
10
example, the first file written is manifest.xml and it expects the file to
be in the root of the project. You can also place
this file in any of the directory of the solution , but in this case you
need to specify the relative path within the ddf file.
4. For the assembly, you recall the location for the Assembly in the
manifest was location=”MyFeature.dll”. The manifest expects this file
to be in the root of the WSP. In your Visual Studio, the path is
bin\Release\MyFeature.dll, so the builder will grab the file from your
bin directory and add it to the WSP’s root.
6. Finally, we write the user control file. The TemplateFile location in our
manifest specifies that it will be located at
“ControlTemplates\MyFeatureForm.ascx”. We will use DestinationDir to
set it to “ControlTemplates” and then write the user control, which is
located in our project at
“12\TEMPLATE\ControlTemplates\MyFeatureForm.ascx”.
7. Similarly we can define other files in the ddf file including its relative
path provided the files should be mentioned in manifest.xml file with
its relative path.
The DDF file only defines how the WSP is build. A utility call makecab does
the actualy work. It reads the DDF file, copies the files in the DDF into the
wsp. One way to have the files generated automatically is to add a script to
the post compile event of your project.
11
cd "$(ProjectDir)"
Now when you compile your project, the event script will run and generate
the WSP file.
12
Creating Build.cmd file
The intent of this file is to generate the wsp file.
1. Create a build.cmd file
2. Edit the file and add the following command
MakeCab /f Package.ddf
3. Running Biuld.cmd file will generate a wsp file in the specified directory
.
13
Creating Installation.bat file
The intent of this file is to install the wsp file to the SharePoint site.
@echo off
@echo on
-allowgacdeployment -force
@pause
1. set path : Defines the 12 hive path of the SharePoint where the package
needs to deploy. In this case we are using “c:\program files\common
files\microsoft shared\web server extensions\12\bin”
2. stsadm -o addsolution-filename: Specifies the wsp file needs to deploy.
3. stsadm -o deploysolution: This command deploys the “MyFeature.wsp” to
the SharePoint site.
4. –url : Specifies the SharePoint site url.
5. –immediate: Allows user to deploy the wsp package immediately to the
SharePoint site.
6. -allowgacdeployment: Deploys the ‘.dll’ files in the GAC if specified in the
ddf and manifest.xml file. It also adds the SafeControl entry in the Web.config
file of the SharePoint site.
14
SharePoint Deployment Graphical Representation
15
Web Part Deployment Example
16
Fig 1: “MyFeature” project structure.
➢ MyFeature.ascx file
17
<td width="25%" >
<img src="~/_layouts/MyFeatureImages/OCS.jpg" />
</td>
<td width="55%">
<asp:Label ID="lblTest" runat=server></asp:Label>
</td>
</tr>
</table>
➢ The assembly tag refers the code behind file for the user control.
➢ Add a new class to the project with name “MyFeatureForm.cs”.
➢ Inherit the class from “System.Web.UI.UserControl” and change the
protection level of class to public partial.
➢ Define the controls used in the “MyFeatureForm.ascx” control as
below
18
Hidden="FALSE" DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="MyFeature\MyFeature.xml" />
<ElementFile Location="MyFeature\MyFeature.webpart" />
</ElementManifests>
</Feature>
Note: Description of the manifest file is explained in “Manifest.xml file and how
it relates to the WSP file” section
➢ Now edit the “MyFeatute.xml” file and change the file path element.
To
<Elements Id="f604cf76-eafe-4299-9f99-9467e3f0a403"
xmlns="http://schemas.microsoft.com/sharepoint/" >
19
<Module Name="WebParts" List="113" Url="_catalogs/wp">
<File Path="MyFeature/MyFeature.webpart" Url="MyFeature.webpart"
Type="GhostableInLibrary" />
</Module>
</Elements>
.OPTION Explicit
.Set CabinetNameTemplate=MyFeature.wsp
.Set DiskDirectoryTemplate=CDROM ; All cabinets go in single directory
.Set CompressionType=MSZIP ; All files compressed in cabinet files
.Set UniqueFiles="ON"
.Set Cabinet=on
.Set DiskDirectory1=Package
manifest.xml manifest.xml
feature.xml MyFeature\feature.xml
..\MyFeature.webpart MyFeature\MyFeature\MyFeature.webpart
..\MyFeature.xml MyFeature\MyFeature\MyFeature.xml
..\..\bin\Debug\MyFeature.dll MyFeature.dll
.Set DestinationDir=CONTROLTEMPLATES
..\..\TEMPLATE\CONTROLTEMPLATES\MyFeatureForm.ascx
.Set DestinationDir=LAYOUTS\MyFeatureImages
..\..\TEMPLATE\LAYOUTS\MyFeatureImages\OCS.jpg
makecab /f MyFeature.ddf
pause
20
@echo off
set path=%path%;c:\program files\common files\microsoft shared\web server
extensions\12\bin
@echo on
stsadm -o addsolution -filename "Package\MyFeature.wsp"
21
➢ Open the files in Explore window.
➢ Run build.cmd file.
➢ It will create “MyFeature.wsp” file.
➢ Run InstallMyFeature.bat file.
22
Fig 3 : Add a Web Part.
23
Fig 4: My Feature Web Part
24