SharePoint 2010 - Create a WebPart & Manual Deployment

Here we are using PowerShell commands along with some manual steps to achieve it.

Using PowerShell

The following are the important steps involved:

  • Create a new Visual Web Part
  • Create a solution file for the Web Part
  • Use PowerShell to add and install the solution
  • Activate the Web Part
  • Insert the Web Part into the site

Create new Visual Web Part

Open Visual Studio 2010 and create a new Visual Web Part template. Name the project and the Web Part as WebPartManualDeployment.

weppart1.jpg

Create Solution file for the Web Part

Now right-click on the Solution Explorer and choose the Package option.

weppart2.jpg

You can find the package file in the BIN\DEBUG folder. (If you are using the Debug Configuration.)

weppart3.jpg

Copy the file path; 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:

  1. Add-SPSolution
  2. Install-SPSolution

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 the GAC.

Enter the command:


Add-SPSolution -LiteralPath "YourPath\WebPartManualDeployment.wsp"

If the command succeededs then 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:

Possible Errors

Error 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 solution "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.

weppart4.jpg

You will see that our Web Part assembly got deployed there.

Once the above steps have 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:

weppart5.jpg

You will get the following screen:

weppart6.jpg

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.

weppart7.jpg

Use the Add button to get the web part added to the site. If you see the screen as shown below, then we are done with the web part deployement.

weppart8.jpg

References

http://technet.microsoft.com/en-us/library/cc261736.aspx
http://msdn.microsoft.com/en-us/library/ff798301.aspx

Summary

In this article we have explored Web Part manual deployment and the aspects involved. The associated source code is attached with the article.

Up Next
    Ebook Download
    View all
    Learn
    View all