What does SPSolution.ContainsWebApplicationResource really mean?

If you look at the documentation for this property on MSDN it says “Gets a value indicating whether the solution contains any web application-specific resources to deploy.”

So, at least to me, it wasn’t totally super clear what a web application specific resource really resource meant.
Let’s see an example to get a better understanding:

The WSP.ContainsWebApplicationResource SharePoint Project

I’ve created a basic SP project in VS 2010 and deployed it, without adding anything to it, to the local farm.
Let’s first see what that gives us:

image

::false

OK, but that was excepted right.

Let’s add a web application scoped feature to it. That should be web application specific…or?

::false

No, a web application scoped feature isn’t web application specific. It can be activated on a web application but it isn’t specific to a specific web application.

How about a site collection scoped feature then? Let’s add site scoped feature (but not include anything in it…emtpy feature).

::false

Strange…? An empty site collection (or site scoped) feature still returns false.

Let’s try adding a web part (or any SPI) to the feature then.

::true

Summary

So it turns out that the ContainsWebApplicationResource really means that the WSP contains elements (in VS those are called SPIs) that are included in a feature that is scoped to either SPSite or SPWeb.

When would you use this property then?

Well, it’s very common to use when you’re writing a PS script that deploys your WSP to the farm…like this little example (sorry about the formatting):

if($SPSolution.ContainsWebApplicationResource) {

$SPSolution | Install-SPSolution -GACDeployment:$ContainsGlobalAssembly
-CASPolicies:$ContainsCasPolicy
-WebApplication $WebApplicationUrl -Confirm:$false -Force -ErrorAction:SilentlyContinue
-ErrorVariable e | Out-Null

}

} else {
$SPSolution | Install-Solution -GACDeployment:$ContainsGlobalAssembly
-CASPolicies:$ContainsCasPolicy
-AllWebApplications:$true -Confirm:$false -Force -ErrorAction:SilentlyContinue -ErrorVariable e | Out-Null

}

If the SPSolution object has web application resources you have the ability to deploy it to one or more web applications, hence I don’t have to deploy it globally across the farm.

,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: