1: install-spsolution Solution.wsp -webapplication "webapplication" -GACDeployment –force
2: install-spsolution Solution.wsp -GACDeployment –force
Which of above is best practice?
You can only deploy a package using -WebApplication if the artifacts in the solution has WebApplication scope. When packaging the solution package Visual Studio will handle this for you detecting the scope of the artifacts.
You will get an error in PowerShell if you try to deploy a solution that has WebApplication scoped artifacts at farm scope and vice versa.
To check if a solution has one scope or another do this
Get-SPSolution <yoursolution.wsp> | Select ContainsWebApplicationResource
SPSolution.ContainsWebApplicationResource can be used to check whether solution contains web application resources or not. In PowerShell scripts, you can use following commands:
# Deploy solution
$Solution = Get-SPSolution | ? {($_.Name -eq $SolutionPackageName) -and ($_.Deployed -eq $false)}
if($Solution -ne $null)
{
if($Solution.ContainsWebApplicationResource)
{
Install-SPSolution -Identity $SolutionPackageName -WebApplication $WebApplication -GACDeployment -Confirm:$false
}
else
{
Install-SPSolution -Identity $SolutionPackageName -GACDeployment -Confirm:$false
}
}