Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

This question already has an answer here:

we are trying to deploy farm solution wsp file on the SharePoint server via PowerShell. The wsp is a webpart. I got this script by browsing forums...

Foll. is our code:-

$oUrl="http://mysite:9999/"    
$solutionPath="C:\MySolutions\"

$solution="FarmSolution.wsp"
$path= $solutionPath + $solution 
Add-SPSolution -LiteralPath $path
install-spsolution -Identity $solution -WebApplication $oUrl -GACDeployment 
WaitForJobToFinish

Using the above PowerShell the wsp gets successfully deployed into the GAC. The webpart can then be added to page and used successfully.

My question is on the foll. line:-

install-spsolution -Identity $solution -WebApplication $oUrl -GACDeployment 

Since the wsp gets deployed to the GAC, then what is purpose of using -WebApplication $oUrl. Can I remove this part? Generally, the only purpose of using the -WebApplication $oURL without following -GACDeployment is to deploy the wsp to inetpub/site/bin.

Now, if our goal is to deploy the wsp to GAC, then why not use it as:-

install-spsolution -Identity $solution -GACDeployment 

Would this be correct?

This question doesnt look to be duplicate of this link as the question addresses the concern of using either -WebApplication or -GACDeployment or both together in powershell to deploy an feature. Also, the answer shows that the value of the 3rd column (Depyoled To) under Manage farm solutions depends upon the use of -WebApplication or -GACDeployment in powershell while deploying as explained by @Waqas Sarwar MCSE which I have marked as an answer.

share|improve this question

marked as duplicate by Muhammad Raja, Falak Mahmood, PirateEric Feb 25 at 21:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers 3

up vote 1 down vote accepted

we use the webapplication switch, if you want to target one web application(Deploys the SharePoint solution for the specified SharePoint web application.)...i.e we have 4 web applications and i want to deploy the solution on 1 web application only, then i will use the this switch, otherwise the webapplication it will deploy the solution to all web application.

GAC deployment means solution available for everybody but it does not mean that every body can use it unless you install it for every web app.

Deploy solution packages (SharePoint Server 2010)

share|improve this answer
2  
You can't target web application for deploying solutions :-), when you deploy a solution, it will get deployed across farm, however you can activate features if they are scoped to web applications on a single web application or all. –  Muhammad Raja Feb 25 at 12:39
    
when you add(add-spsolution) the solution, then it will added to all server, but when you deploy it(install) then you can target it to web application...you can check from central admin > manage farm solution > from there you will see the deploy option...to all or a specific web app. –  Waqas Sarwar MCSE Feb 25 at 12:45
    
Yes, Waqas has a point as I have seen some farm solutions showing 3rd column as Deployed globally or the web address. Waqas, why this happens? Is it because of setting the scope under visual studio? –  variable Feb 25 at 12:50
    
I noticed that if script is install-spsolution -Identity $solution -GACDeployment then it comes as globally deployed. Where as if we specify the -WebApplication $oUrl -GACDeployment then it shows website address in 3rd column... –  variable Feb 25 at 12:54
    
@NachiketKamat and Waqas, do me a favour and develop a web application scoped feature, deploy it as a solution to a specific webapplication, now look at all other web applications, they will let you activate the feature on them, Above answer is just a logical explanation, not what happens in real... :) –  Muhammad Raja Feb 25 at 13:08

In short, yes because it's an optional parameter,

WebApplication

Optional

Microsoft.SharePoint.PowerShell.SPWebApplicationPipeBind

Deploys the SharePoint solution for the specified SharePoint web application. The value must be in one of the following forms:

An authentic GUID, in the form 12345678-90ab-cdef-1234-567890bcdefgh

An authentic name of a SharePoint web application (for example, MyOfficeApp1)

An instance of an authentic SPWebApplication object.

Reference

If you won't going to provide WebApplication parameter, it will deploy solution to all web application.

This parameter is useful when your solution or feature is SPWebApplication scope and it going to make changes to specific web application. For example web.config changes, as said by Nadeem.

Edit

Saying all that documented, it's not easy to understand, here is an example I came across in past,

Moss Timer job deployed in one web application but running in a different web application

share|improve this answer
    
Farm solution can be scoped at web application, site collection and site level. So what exactly happens when suppose your solution or feature is SPWebApplication scope and you use script as --> install-spsolution -Identity $solution -WebApplication $oUrl -GACDeployment --> and what would happen if you didnt use the -WebApplication $oUrl ?? –  variable Feb 25 at 12:42
    
@NachiketKamat If you have resources that are scoped to web application level within your solution, then they will only be added to deployed solution, but if there isn't anything there it won't going to add anything to web applications, so using web application parameter becomes useless. –  Muhammad Raja Feb 25 at 13:03
    
Even with GAC deployment you can target to one web application...you have some requirement which needs gac deployment but you dont want that solution for all web apps then you use this switch to focus the web app...solution will available in farm for every body but only one web app will see because we target it. –  Waqas Sarwar MCSE Feb 25 at 13:14
    
@WaqasSarwarMCSE solution will available in farm for every body but only one web app will see because we target it. Please provide me some reference for this statement with example :-) –  Muhammad Raja Feb 25 at 14:14

Since your WSP contains a webpart, it has safe control entries. And safe control entries are added to web.config files. Generally you make a check while deploying the solutions:

if($Solution.ContainsWebApplicationResource)   
{
    Install-SPSolution -Identity $SolutionPackageName -WebApplication $WebApplication -  GACDeployment -Confirm:$false
}
else
{
    Install-SPSolution -Identity $SolutionPackageName -GACDeployment -Confirm:$false
}

You can very well remove the -WebApplication parameter from a solution which has web application resources. In that case safe control entries will be added to all web.config files of all web applications. However, if you try to deploy a solution with no such resoureces using -WebApplication aparemeter it will give error that "this solution contains no resources scoped for a web application"

share|improve this answer
    
When does ContainsWebApplicationResource come true? Only when it is webpart? Is the purpose of using -WebApplication $WebApplication to add node to web.config? –  variable Feb 25 at 13:01
    

Not the answer you're looking for? Browse other questions tagged or ask your own question.