Packaging and deploying the SharePoint solution

Visual Studio provides a simple one-click method to package a SharePoint project as a SharePoint solution. Once packaged, solutions can be deployed from the Visual Studio interface. In addition, packaged solutions can be deployed with PowerShell and .NET code.

How to do it...

Follow these steps to package and deploy the solution:

  1. From the Solution Explorer pane, right-click on the project name.
  2. Select Publish as shown in the following screenshot:
    How to do it...
  3. Provide a location to output the SharePoint solution file.
  4. Click on Publish.
    How to do it...
  5. From the BUILD menu, select Deploy Solution as shown in the following screenshot:
    How to do it...

How it works...

When Visual Studio publishes (or packages) a SharePoint project, it creates a SharePoint solution file (wsp) that contains a manifest, the assemblies, and any other files that are included. The SharePoint solution is then outputted to the folder specified.

In addition, Visual Studio has the ability to deploy the solution to the local SharePoint server from the Visual Studio interface. Using this method, we will retract the solution if it already exists, and then add and deploy the solution.

There's more...

Deploying SharePoint solutions can also be accomplished with PowerShell or code using the server-side object model.

Deploying a solution using PowerShell

Follow these steps to deploy a solution using PowerShell:

  1. Use the Add-SPSolution Cmdlet to add the solution to the SharePoint farm using the following code:
    Add-SPSolution -LiteralPath "C:PackagesCode6587EN.Ch04.wsp"
    
  2. Use the Install-SPSolution Cmdlet to deploy the solution to the SharePoint farm.

    Certain code, such as our custom timer job, requires the assembly to be in the Global Assembly Cache on the SharePoint servers so that the SharePoint Timer service can access it. To ensure our assembly gets added to the Global Assembly Cache, we will use the –GACDeployment parameter as follows:

    Install-SPSolution Code6587EN.Ch04.wsp -GACDeployment
    

    Tip

    When deploying SharePoint solutions on a large scale, it is prudent to check if the solution already exists on the farm in order to upgrade the solution rather than installing it. In addition, if the solution contains web application resources, such as safe control entries, the Install-SPSolution Cmdlet will need to target web applications.

    The code sample included with this book for this recipe illustrates an example of identifying these parameters before performing the appropriate action.

Deploying a solution with code using the server-side object model

Follow these steps to deploy a solution with code using the server-side object model:

  1. Add the following SharePoint solution to the solutions' collection on the local SharePoint farm:
    var farmSolution = SPFarm.Local.Solutions.Add("C:\Packages\Code6587EN.Ch04.wsp");
    
  2. Deploy the SharePoint solution globally using the following command:
    farmSolution.Deploy(DateTime.Now, true, false);
    

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.176.228