开发者

Applying a custom webtemplate to a sitecollection works on powershell ise and not on powershell console

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 sitecol开发者_开发百科lection.

Any ideas? thanks!


Is there any chance you are running 64-bit ISE and 32-bit PowerShell console (or vice-versa)? If it's not that then another difference is that ISE runs in COM STA mode whereas PowerShell Console runs in MTA by default. This would only matter if SharePoint uses COM under the covers (which I think it does). You could verify this by running PowerShell Console in STA mode like so:

C:\> Start-Process PowerShell -arg -sta

Assuming you're on PowerShell 2.0 for the Start-Process cmdlet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜