In this article I would like to explore the multiple ways of deploying a Web Part into SharePoint server. Here we are using PowerShell commands along with some manual steps to achieve it.
Following are the important steps involved:
· Create new Visual Web Part
· Create Solution file for the Web Part
· Use PowerShell to Add and Install Solution
· Activate the Web Part
· Insert the Web Part into site
Create new Visual Web Part
Open Visual Studio 2010 and create new Visual Web Part template. Name the project and the Web Part as WebPartManualDeployment.
Create Solution file for the Web Part
Now right click on the Solution Explorer and choose the Package option.
You can find the package file in the BIN\DEBUG folder. (if you are using Debug Configuration)
Copy the file path and we need to use this in the next step.
Use PowerShell to Add and Install Solution
Now open the PowerShell window. We need to execute the following Cmdlets.
The first command adds the solution into the SharePoint farm.
The second command extracts and installs the solution. It includes activities like deploying assemblies to GAC.
Enter the command:
Add-SPSolution -LiteralPath "YourPath\WebPartManualDeployment.wsp"
If the command succeeded please continue with the following command.
Install-SPSolution -Identity "WebPartManualDeployment.wsp" -GACDeployment -WebApplication http://yourservername/
Some of the possible errors you could receive are listed here:
| Solution |
| Install-SPSolution : Admin SVC must be running in order to create deployment timer job.
| Open services.msc and start the service named SharePoint 2010 Administration. |
| Install-SPSolution : A deployment or retraction is already under way for the so
lution "webpartmanualdeployment.wsp", and only one deployment or retraction at
a time is supported.
| Go to Central Administration > System Settings > Manage farm solutions > Cancel / Retract the particular solution |
After the installation step, your web part assembly gets deployed to the GAC. You can type open the assembly folder and verify it.
You can see that our Web Part assembly got deployed there.
Once the above steps succeeded we can move to the next step.
Activate the Web Part
Now open your site and select Site Actions > Site Settings > Site collection features
You will get the following screen:
Click on the Activate button.
Note: Please note that the sandboxed solution assembly is not copied to the GAC until you specify GAC explicitly. For more information you can use the Reference links.
Insert the Web Part into site
Now we are ready to use the new web part in our site. Open the site and go to Site Actions > Edit Page. From the Insert tab click the Web Part button. You will be getting the following list. Choose the Custom item from the first pane and our web part should be listed there.
Use the Add button to get the web part added to the site. If you can see the screen as below, then we are done with the web part deployement.
In this article we have explored Web P
art manual deployment and the aspects involved. The associated source code is attached with the article.