Here are some useful PowerShell commands for simple SharePoint 2010 deployment. This article is for those who are learning SharePoint and not for the SPGurus.
I keep my SharePoint 2010 in a VM (Oracle VirtualBox) and Visual Studio 2010 on the host. Its just easy to work with IDEs on the host rather than VM. That way, when a code inspiration strikes you, it will not fade away until the VM opens up. Also, Visual Studio 2008 had this annoying-much-complained-about-screen-flickering issue when working from within a VM (atleast Windows Virtual PC). Not sure if it went away for VS 2010.
Anyway, I was disappointed to see Visual Studio 2010 cannot create SharePoint projects if SP 2010 Server is not installed on the same machine. Dumb move. Very dumb. And the workaround? Simply export the “14” registry key from a SP2010 Server and import into local machine. Your local machine thinks you have SharePoint Server, but you really only installed a Name of the Server. Now VS 2010 allows you to create a project, but you have the itch to click that Validate button, isnt it? Well, survive the itch and just press Finish and the SharePoint project is now created. Go figure! Microsoft could have had some brownie points making this feasible out of the box.
Next, you cannot deploy a wsp directly into the VM. And the workaround? Deploy the solution locally, copy it to a shared directory, use PowerShell within the VM and deploy. Could have been made simple… Er, Could…Er.
Let us assume you created the simplest “Please-start-with-me” project – VisualWebPart1. Here are some powershell commands and shortcuts to make this deployment simple:
Edit the project properties and create a new deployment configuration, which does only Pre-command Line and Post command Line. In the Post-Command Line text box, add a dos command to copy the wsp file to a shared folder with VM.
For the first time, you need to execute the following commands in PowerShell for SharePoint.
Catch: This is not the regular Windows 2008 PowerShell, but the SharePoint Management PowerShell, located within the SharePoint Programs shortcuts:
Add-SPSolution -literalpath c:\VisualWebPartProject1.wsp
Install-SPSolution -identity VisualWebPartProject1.wsp -allwebapplications -gacdeployment
;Verify the solution if installed
Enable-SPFeature -identity VisualWebPartProject1_Feature1 -url http://yoursiteurl/
Get-SPFeature | Sort-Object DisplayName
Next time around, just Deploy from VisualStudio 2010, switch to the VM and execute this:
Update-SPSolution -literalpath c:\VisualWebPartProject1.wsp -identity VisualWebPartProject1 -GACDeployment
When you modify the solution, SharePoint recycles IIS anyway, so any of those default VisualStudio recycle commands are really superfluous.