Hi all, I'm working on a automated script for deploying sharepoint projects. I'm using a sandbox level webtemplate that must be applied when de site is created. I had a lot of troubles doing that because it seems like sharepoint caches the list of webtemplates and get-spwebtemplate doens't find the new added one. The way I made it work is this:
[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")
$site= new-Object Microsoft.SharePoint.SPSite($web_application_complete_url)
$site.OpenWeb().ApplyWebTemplate($web_template_name)
$site.Dispose()
As you can see, I'm using the .net sharepoint api instead of the cmdlets. This works sweet in PowerShell ISE but in the PowerShell console it throws an exception regarding a referenced DLL:
Exception calling "ApplyWebTemplate" with "1" argument(s): "Could not load file or assembly 'XXX.SharePoint.Common, Version=1.0.0.0, Culture=neutral, PublicK eyToken=534c125b45123456' or one of its dependencies. The system cannot find th e file specified." At C:\Build\SharePointBuild.p s1:318 char:37 + $site.OpenWeb().ApplyWebTemplate <<<< ($web_template_name) + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordE xception + FullyQualifiedErrorId : DotNetMethodException
The assembly is perfectly registered in the GAC when installing the web template sandbox solution in the sitecollection.
Any ideas? thanks!