The second part of my SharePoint 2010 developer learning is about Sandboxed Solutions. It ships with SharePoint Foundation 2010 and SharePoint Server 2010 and allows you to upload solutions to a site collection without the need of a farm administrator.
This is the second part of a series describing my attempt to become a SharePoint 2010 developer using available resources.
Resources
First of all here are the resources I used:
Videos and Podcast
The first link includes 5 videos and the second link includes 2 videos with Andrew Connell.
MSDN
Blog posts
There is also a discussion going on if sandboxed solutions are useful or not… just check the links and the comments:
Using SharePoint 2010 – Sandboxed Solutions
The resources above cover a lot of things but one thing wasn’t clear to me: what if I don’t use the Visual Studio 2010 SharePoint extensions?
Sandboxed or not sandboxed?
Using the Visual Studio 2010 SharePoint extensions there is a project property which decides if a solution is sandboxed or not. If you change you will get a message from Visual Studio:
In my opinion this property only limits the code completion feature:
There is no property in the manifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<Solution xmlns="http://schemas.microsoft.com/sharepoint/"
SolutionId="d65c99e3-132e-4ade-b748-fe8a1b876dcf">
<Assemblies>
<Assembly Location="Module 9 - Sandboxed Solutions.dll"
DeploymentTarget="GlobalAssemblyCache">
<SafeControls>
<SafeControl Assembly="Module 9 - Sandboxed Solutions, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=be9c0679755f57e7"
Namespace="Module_9___Sandboxed_Solutions.Module_9___SandBoxedWebPart"
TypeName="*" />
</SafeControls>
</Assembly>
</Assemblies>
<FeatureManifests>
<FeatureManifest Location="Module 9 - Sandboxed Solutions_Feature1\Feature.xml" />
</FeatureManifests>
</Solution>
At the end the project property from Visual Studio helps the developer to implement sandboxed solutions which can run in the SPUCWorkerProcess.exe by limiting intelli sense. I think there is no other use of this property regarding the deployment process.
Deployment
How do you deploy a sandboxed solution without Visual Studio 2010?
Deploying a sandboxed and a not sandboxed solution to the farm solution store
Both is possibly. There is no difference if you install a sandboxed or a not sandboxed solution using stsadm.exe. You can also deploy both to a web application and use it.
stsadm.exe
stsadm.exe -o addsolution
-filename <Solution filename>
[-lcid <language>]
C:\Users\spadmin>STSADM.EXE -o addsolution -filename Module_9___Sandboxed_Solutions.wsp
Operation completed successfully.
C:\Users\spadmin>
This example is a Visual Studio 2010 sandboxed solution which I added to the farm solution store and deployed it to a web application:
Here you can see one of the video examples from above. All of the buttons with code behind can be executed which isn’t possibly if you deploy this demo to a site collections solution gallery.
PowerShell
You can also use PowerShell for deploying farm solutions:
SYNTAX
Add-SPSolution -LiteralPath <String> [-AssignmentCollection <SPAssignmentCollection>]
[-Confirm [<SwitchParameter>]] [-Language <UInt32>] [-WhatIf [<SwitchParameter>]] [<CommonParameters>]
Deploying a sandboxed and a not sandboxed solution to the site collection solution gallery
You can’t add a sandboxed solution by using stsadm.exe. You have to use PowerShell or you have to do it manually by using the user interface.
PowerShell
SYNTAX
Add-SPUserSolution -LiteralPath <String> -Site <SPSitePipeBind> [-AssignmentCollection <SPAssignmentCollection>]
[-Confirm [<SwitchParameter>]] [-WhatIf [<SwitchParameter>]] [<CommonParameters>]
You can add sandboxed and not sandboxed solutions to the site collection solution gallery. Here I added a not sandboxed solution:
Note: Unfortunately I wasn’t able to add the WebPart from the solution but I think this is an other problem which I faced a few times.
Compile a sandboxed solution - tip
Here is a tip by Andrew Connell (from the second Chanel 9 video): You can compile your sandboxed solution by using a reference to the user code assembly. Now you will get an error if you are using code which can’t be run using sandboxed solutions. Don’t forget to reference the original assembly after the test.
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\UserCode\assemblies\Microsoft.SharePoint.dll
Note: I used the SharePoint 2010 beta for this article.
Summary
So at the end every type of solution can be added to the farm solution store or the site collection solution gallery. It doesn’t matter. What matters is the code behind which can be executed by the w3wp.exe and the SPUCWorkerProcess.exe or not.