SharePoint Study Notes-use powershell to add and deploy solution

Source: Internet
Author: User
Tags visual studio 2010

We usually use Visual Studio 2010 to quickly develop and deploy our SharePoint solution. but sometimes we have to deploy the solution packages we developed to other physical locations (production machines), rather than the servers (Test Machines) that our development environment directs ). Previously we used stsadm to do this, but now we recommend using powershell.
The following describes the basic steps involved in this job:
1. Add solution to SharePoint farm
We need to package the solution in Visual Studio first. The packaged package can be found in the bin \ DEBUG directory of solution. Copy the solution package under this directory to the specified directory on the server to be deployed. For example: D: \ sp2010 \ deploysolution \ my1_pointproject. WSP
If you use the previous stsadm to add solution, yes

Stsadm-O addsolution-name D: \ sp2010 \ deploysolution \ mysharepointproject. WSP

To use powershell, you only need to find

The system automatically loads Microsoft. sharepoint. powershell, we can directly execute the powershell command we want to execute in its command window. if you have usage problems with a powershell command (such as add-spsolution), you can use get-help add-spsolution in its command window to obtain help related to this command.
Here, we use the powershell command to add solution:

Add - Spsolution D: \ sp2010 \ deploysolution \ mysharepointproject. WSP

If you are developing sandboxed solution, you need to use the add-spusersolution command to execute the above operations. This command requires the parameter-literalpath, which points to the full path of solution,
2. Deploy solution to the specified Web Application
Next we will deploy solution to the Web application we specified (eg: http: // myserver-sp1: 2010 /)
If the previous stsadm is used to complete the deployment solution

Stsadm-O deploysolution-name mydomainpointproject. WSP-URL http: // Myserver-sp1: 2010/-allowcaspolicies-immediate

If you use the powershell command

Install - Spsolution-identity mydomainpointproject. WSP-webapplication http: // Myserver-sp1: 2010/-gacdeployment

If sandboxed solution is deployed, run the install-spusersolution command.
-gacdeployment parameter can also be changed to-caspolicies, the difference between the two is that
gacdeployment specifies that the global Program set cache (GAC )..
caspolicies indicates that the Code access security (CAS) policy can be deployed for the new SharePoint solution.
-The webapplication parameter can also be changed to-allwebapplications. The difference between the two is:
webapplication: deploy a Sharepoint solution for the specified SharePoint web application. This type must be a valid guid in the format of 12345678-90ab-cdef-1234-567890bcdefgh.

A valid name for a Sharepoint web application (for example, myofficeapp1) or an instance of a valid spwebapplication object.

Allwebapplications: Specify to deploy a new SharePoint solution for all SharePoint Web applications in the server farm.

If you need to forcibly deploy this solution, you can use the-force parameter.
After the preceding steps, you can add and deploy the specified SharePoint solution package to the specified SharePoint farm and web application. In order to make this article more complete, we will continue to discuss other work we may want to do.
3. Upgrade and deploy solution.
We may need to use the Upgrade Method to deploy the solution we have already deployed. before using this method, we need to copy the solution of the new version to the directory we specified. For example: D: \ sp2010 \ deploysolution \ mydomainpointproject. WSP
If you use the stsadm command:

Stsadm-O upgradesolution-name mydomainpointproject. WSP-filename D: \ sp2010 \ deploysolution \ mydomainpointproject. WSP-immediate-allowcaspolicies

 To use the powershell command:

Update - Spsolution-identity mydomainpointproject. WSP-literalpath D: \ sp2010 \ deploysolution \ mydomainpointproject. WSP-gacdeployment

4. Reclaim deployed Solution
Previously, we have completed the instll, deploy, and upgrade operations. Next we will implement the uninstall operation, which will reclaim solution from the specified (or all) webapplication. Solution still exists in farm, but is not allocated to webapplication.
Run the powershell command:

Uninstall - Spsolution-identity mydomainpointproject. WSP-webapplication http: // Myserver-sp1: 2010/

We can also use the-allwebapplications parameter to reclaim solution from all web applications where this solution is deployed in SharePoint farm.
When you execute this command, the system will prompt:. "Are you sure ?" You only need to be sure to perform the operation.

5. Remove Solution
This is the last step. We will remove the installed solution from SharePoint farm.
Run the powershell command:

Remove - Spsolution-identity mydomainpointproject. WSP

If stsadm is used to complete steps 4 and 5 aboveIn general, we can create a batch processing file eg: deletesolution. bat
The Code content is as follows (the content should be modified according to your own situation ):

: Begin
@ Echo off
Rem ** Declare the solution to be retracted **
Set Solutionname = Samplesolution
Rem ** Declare Set Of fetures to be de - Activated **
Set Featuresamplefeature1 = Samplefeature1
Set Featuresamplefeature2 = Samplefeature2
Set Featuresamplefeature3 = Samplefeature3
Rem ** Replace This Value with the URL of your site **
@ Set URL = HTTP: // Servername/sites/sitecollectioname/sitename
@ Set path = C: \ Program Files \ common files \ microsoft shared \ Web Server Extensions \ 12 \ Bin; % Path %  
Echo deactivating features In Solution % Solutionname % ...
Echo ----------------------------------------------------
Stsadm - O deactivatefeature - Name % Featuresamplefeature1 %   - URL % URL %   - Force
Stsadm - O deactivatefeature - Name % Featuresamplefeature2 %   - URL % URL %   - Force
Stsadm - O deactivatefeature - Name % Featuresamplefeature3 %   - URL % URL %   - Force
Echo attempting to uninstallfeature and retract Solution
Echo ---------------------------------------------------
Echo rectracting Solution % Solutionname % From Solution store...
Stsadm - O retractsolution - Name % Solutionname % . WSP - Immediate
Stsadm - O execadmsvcjobs
Echo deleting Solution % Solutionname % From Solution store...
Stsadm - O deletesolution - Name % Solutionname % . WSP - Override  
Echo.
If Errorlevel =   0   Goto : Success
: Success
Echo successfully deployed solution and activated feature (s )..
Echo.
Goto End
: End
Pause

Related links:

SharePoint Study Notes-use stsadm installing or uninstalling features

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.