Adding a reference to a shared library from a web part is not as simple as using visual studio to add a reference to a project output or a fixed DLL on the file system. In addition to adding the reference to the project itself, you must add the DLL to the cab file and modify the manifest.xml so that the referenced DLL is deployed with the web part. This How To shows you what must be done for the web part to deploy correctly when referencing another assembly.
Adding the reference to the project
Adding the reference to the project can be done with the following steps:
- Right Click References under the web part project and click Add Reference…
- Click the Projects tab.
- Click the project and click Select or double-click the project so that the project appears in the Selected Components list at the bottom of the dialog.
- Click the OK button.
Now you have added the reference to the project. Next is adding the DLL to the CAB file.
Adding the Referenced DLL to the CAB file
The process of adding the referenced DLL to the CAB file is easy. Simply follow these steps:
- Right click the setup (CAB) project, select Add from the context menu, and finally Project Output…
- Select the correct project for the output file in the Project drop down at the top of the dialog.
- Click the Primay output item in the list.
- Click the OK button.
Now that you’ve added the DLL to the Cab file it’s time to add the file to the manifest.xml.
Adding the Reference to Manifest.xml
The final step is to add the file to manifest.xml so that STSADM will deploy the DLL for you when the web part is deployed. You can do this by following these steps:
- Open the manifest.xml file for the web part project in Visual Studio
- Locate the </Assemblies> tag.
- Add a new tag <Assembly FileName=”” /> immediately before the </Assemblies> tag
- Add the name of the referenced DLL to the FileName attribute of the <Assembly> tag that you just added. Note that the name should not include any path information. It should be the complete name of the referenced DLL—including the DLL extension.
- Safe the file.
Now you have completed the changes necessary for the web part project to deploy the referenced DLL along with your web part.
No comment yet, add your voice below!