Some Visual Studio solutions I’ve come across have class library projects in them. These assemblies have to subsequently be manually copied into the GAC of each SharePoint server. This goes against the standard of using wsp files to deploy assemblies and files into a SharePoint environment. Single servers are easier to manage manually copying assemblies but it’s not a very pleasant way of doing things, move into a multi server environment and you’re in a minefield.
Fortunately there is an easy way to get these assemblies, plus any others you may wish to deploy at the same time, into a wsp. It takes two files and a post build event. Read on..
First up, we need a manifest file. This tells the environment what we would like it to do with the assembly.
Create a new xml file in the root of your project called manifest.xml and add the following code:
<solution xmlns="http://schemas.microsoft.com/sharepoint/" solutionid=""> <assembly location=".dll" deploymenttarget="GlobalAssemblyCache">
Replace <new guid> with a generated GUID and <assembly> with the name of your dll file.
The DeploymentTarget attribute above specifies that it will be deployed to the GAC, you can use WebApplication if you want it to be deployed to the bin directory of your Webb Application.
You can also specify that the relevant line can be added to the SafeControls section of your web.config file by adding the following inside the Assembly tag above.
<safecontrol assembly=", Version=126.96.36.199, Culture=neutral, PublicKeyToken= " namespace="" typename="*" safe="True">
Next up, create a ddf file in the root of your project. I tend to name mine wsp.ddf for consistency. This will contain the instructions on what to package into the wsp file. This file should look like the following.
;Define the output directory and CAB file name (with a wsp extension) .Set DiskDirectory1="bin\Debug" .Set CabinetNameTemplate="MySolutionName.wsp" ;Include the following files in the CAB Root manifest.xml bin\Debug\.dll
Now all we have left to do is add a post build event to build the wsp for us.
Go to you project properties (right click project)
Under the Build Events tab under Post-build event command line, enter the following:
:: Change directory to the root of the project cd "$(ProjectDir)" :: Create a WSP CAB MakeCAB /f "WSP.DDF"
You can change when the post build event runs, to your liking; normally ‘On successful build’.
That’s it when you have a successful build the wsp file will be generated ready for you to deploy, no more manual copying or editing web.config.