One of the greatest development features in MOSS is the ability to create solution files which can be managed and deployed across your development landscape as you moved towards production. When a solution is deployed, all files inside are deployed to the correct locations, which is extremely helpful in a load balanced environment.
I'll demonstrate here what it takes to get a solution up and running from scratch. This is the template I use for all my new WSP files.
Create a class library project in Visual Studio. I'll name mine 'SampleWSSSolution'. Once the project has loaded, right click on the project name in the project explorer, and click 'Properties'. On the 'Signing' tab, click the checkbox 'Sign the assembly' and in the drop down choose '<new>'. In the 'Create Strong Name Key' popup, enter 'SampleWSSSolution' in the 'Key file name:' text box, and uncheck the 'Protect my key file with a password' checkbox.
In the same project properties screen, click the 'Build Events' tab, and enter the following into the 'Post-build event command line:' text area:
cd $(ProjectDir)
makecab /f CreateSolutionCAB.ddf
This code will create the WSP file in the root directory of the project.
Now, create four files in the VS project:
- CreateSolutionCAB.ddf
- manifest.xml
- Deploy.cmd
- Upgrade.cmd
Here's what the contents of the files should look like:
CreateSolutionCAB.ddf
This file tells makecab.exe what files to put into the CAB file
-----------------------------------------------------------------------
.OPTION EXPLICIT ;generate errors
.Set CabinetNameTemplate=SOLUTIONNAME.wsp
.Set DiskDirectoryTemplate=CDROM ;All cabinets go into a single directory
.Set CompressionType=MSZIP ;** All files are compressed in cabinet files
.Set UniqueFiles="ON"
.Set Cabinet=on
.Set DiskDirectory1=
;Here's the way it works...
;FileToCopyFromInProject NewFileInCABFile
;manifest file
manifest.xml manifest.xml
;features
FeatureName\feature.xml FeatureName\feature.xml
FeatureName\elements.xml FeatureName\elements.xml
;aspx pages
CustomPageDirectoryName/default.aspx LAYOUTS\CustomPageDirectoryName\default.aspx
FeatureName\FeaturePageName.aspx LAYTOUS\DirectoryName\FeaturePageName.aspx
;web parts
WebPartDirectoryName\feature.xml WebPartDirectryNameInFEATURES\feature.xml
WebPartDirectoryName\elementmanifest.xml WebPartDirectryNameInFEATURES\elementmanifest.xml
WebPartDirectoryName\WebPartName.webpart WebPartDirectryNameInFEATURES\WebPartName.webpart
;assemblies
bin\debug\SampleWSSSolution.dll SampleWSSSolution.dll
----------------------------------------------------------------------------------------------------------------------------
manifest.xml
This file is the manifest of the solution and tells WSS the contents and where to put them once it is deployed
----------------------------------------------------
<Solution SolutionId="GUID" xmlns=http://schemas.microsoft.com/sharepoint/
ResetWebServer="TRUE">
<FeatureManifests>
<FeatureManifest Location="WebPartDirectryNameInFEATURES\feature.xml"/>
<FeatureManifest Location="FeatureName\feature.xml"/>
</FeatureManifests>
<TemplateFiles>
<TemplateFile Location="LAYOUTS\CustomPageDirectoryName\default.aspx"/>
<TemplateFile Location="LAYTOUS\DirectoryName\FeaturePageName.aspx"/>
</TemplateFiles>
<Assemblies>
<Assembly DeploymentTarget="GlobalAssemblyCache" Location="SampleWSSSolution.dll">
<SafeControls>
<SafeControl Assembly="SampleWSSSolution, Version=1.0.0.0, Culture=Neutral,
PublicKeyToken=assembyPublicKeyToken"
Namespace="SampleWSSSolution" TypeName="*"/>
</SafeControls>
</Assembly>
</Assemblies>
</Solution>
-------------------------------------------------------------------------------------------------------
Deploy.cmd
----------------------------------------------------
REM ----- Deactivate the feature(s) -----
stsadm -o deactivatefeature -name FEATURENAME -url "http://www.sitecollectionurl.com" -force
REM ----- Remove the features and solution -----
stsadm -o retractsolution -name SampleWSSSolution.wsp -immediate -url
"http://www.sitecollectionurl.com"
ECHO OFF
ECHO .
ECHO .
ECHO -------------------------------------------------------------------------------------------
ECHO Verify that the correct solutions have been completly retracted and then press ENTER
ECHO -------------------------------------------------------------------------------------------
ECHO .
pause
ECHO ON
REM ----- Delete the solution -----
stsadm -o deletesolution -name SampleWSSSolution.wsp
REM ----- Add and depoly the solution -----
stsadm -addsolution -filename SampleWSSSolution.wsp
stsadm -deploysolution -n SampleWSSSolution.wsp
-immediate -allowgacdeployment
-url "http://www.sitecollectionurl.com"
ECHO OFF
ECHO .
ECHO .
ECHO -------------------------------------------------------------------------------------------
ECHO Solution deployment complete, press ENTER to activate features, if any
ECHO -------------------------------------------------------------------------------------------
pause
ECHO ON
REM ----- Active features -----
stsadm -o activatefeature -name FEATURENAME -url "http://www.sitecollectionurl.com" -force
REM ----- Remove the following comment if features are present
REM pause
----------------------------------------------------------------------------------------------------------------------
Upgrade.cmd
-------------------------------------------------
cls
REM ----- Deactivate the feature(s) -----
stsadm -o deactivatefeature -name FEATURENAME -url "http://www.sitecollectionurl.com" -force
ECHO OFF
ECHO .
ECHO .
ECHO -------------------------------------------------------------------------------------------
ECHO Verify that the correct solutions have been completly retracted and then press ENTER
ECHO -------------------------------------------------------------------------------------------
ECHO .
pause
ECHO ON
REM ----- Upgrade the solution -----
stsadm -upgradesolution -n SOLUTIONNAME.wsp
-filename SOLUTIONNAME.wsp
-immediate -allowgacdeployment
-url "http://www.sitecollectionurl.com"
ECHO OFF
ECHO .
ECHO .
ECHO -------------------------------------------------------------------------------------------
ECHO Solution deployment complete, press ENTER to activate features, if any
ECHO -------------------------------------------------------------------------------------------
pause
ECHO ON
REM ----- Active features -----
stsadm -o activatefeature -name FEATURENAME -url "http://www.sitecollectionurl.com" -force
REM ----- Remove the following comment if features are present
REM pause
----------------------------------------------------------------------------------------------------------------------------
If you have features in the solution, make sure you add the following line to the <assemblies> section of the web.config of your web application
<add assembly="SampleWSSSolution, Version=1.0.0.0, Culture=neutral, PublicKeyToken=assemblyPublicKeyToken" />
Now you can create features, web parts, web services, etc. Just make sure you change the placeholder content in the different files to the correct names of the features you create. Once you're finished creating the solution, run the Deploy.cmd file and the solution will be added to the Solution Management section of the Operations tab in Central Admin
So, when do you use Deploy.cmd and when do you use Upgrade.cmd?
Use deploy for the first deployment of the solution, or for local development deployments where you need to deactivate the features as well as remove the solution for a clean install. Upgrade will run -upgradesolution which updates deployed files, such as the assembly and aspx files. This works great for re-deploying Page Layout files that are already being used in production. I'll most likely post on the Publishing deployment process soon...