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.
Follow these steps to package and deploy the solution:
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.
Deploying SharePoint solutions can also be accomplished with PowerShell or code using the server-side object model.
Follow these steps to deploy a solution using PowerShell:
Add-SPSolution
Cmdlet to add the solution to the SharePoint farm using the following code:Add-SPSolution -LiteralPath "C:PackagesCode6587EN.Ch04.wsp"
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
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.
Follow these steps to deploy a solution with code using the server-side object model:
var farmSolution = SPFarm.Local.Solutions.Add("C:\Packages\Code6587EN.Ch04.wsp");
farmSolution.Deploy(DateTime.Now, true, false);
18.191.176.228