Tor*_*and 7 deployment powershell sharepoint visual-studio-2010 sharepoint-2010
我编写了一个脚本,将一些测试数据插入到文档库中.我打算将它用作Visual Studio 2010中的部署后步骤,以便在收回和部署后库不为空.
脚本的相关部分是:
Install.ps1:
$scriptDirectory = Split-Path -Path $script:MyInvocation.MyCommand.Path -Parent
. "$scriptDirectory\Include.ps1"
$webUrl = "http://localhost/the_site_name"
$web = Get-SPWeb($webUrl)
...
Run Code Online (Sandbox Code Playgroud)
Include.ps1:
function global:Get-SPSite($url)
{
return new-Object Microsoft.SharePoint.SPSite($url)
}
function global:Get-SPWeb($url,$site)
{
if($site -ne $null -and $url -ne $null){"Url OR Site can be given"; return}
#if SPSite is not given, we have to get it...
if($site -eq $null){
$site = Get-SPSite($url);
...
}
Run Code Online (Sandbox Code Playgroud)
从命令行运行时,它工作正常,甚至在Visual Studio重新部署后立即执行:
powershell \source\ProjectFiles\TestData\Install.ps1
但是,当我在Visual Studio的SharePoint项目属性中使用与部署后命令行完全相同的命令时,它不起作用:
Run Post-Deployment Command:
New-Object : Exception calling ".ctor" with "1" argument(s): "The Web applicati
on at http://localhost/the_site_name could not be found. Verify that you have t
yped the URL correctly. If the URL should be serving existing content, the syst
em administrator may need to add a new request URL mapping to the intended appl
ication."
At C:\source\ProjectFiles\TestData\Include.ps1:15 char:18
+ return new-Object <<<< Microsoft.SharePoint.SPSite($url)
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvoca
tionException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power
Shell.Commands.NewObjectCommand
有趣的是,如果我运行,我可以在命令行上重现错误:
c:\windows\Syswow64\WindowsPowerShell\v1.0\powershell \source\ProjectFiles\TestData\Install.ps1
但是,即使我明确地运行\windows\System32\WindowsPowerShell\v1.0\powershell和,部署后命令也会失败\windows\Syswow64\WindowsPowerShell\v1.0\powershell.
更新:找到解决方案
我似乎遇到了与此处讨论的问题类似的问题:
我无法使用32位客户端访问64位SharePoint API.由于Visual Studio是32位,因此部署后操作将在32位进程中运行,并且将失败.但是,有一个64位的MSBuild.如果我们让它运行PowerShell脚本,一切都很好.
将脚本包装在MSBuild文件中,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Install" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Install">
<Exec Command="powershell .\Install" />
</Target>
</Project>
Run Code Online (Sandbox Code Playgroud)
然后,将部署后命令行设置为:
%WinDir%\Microsoft.NET\Framework64\v4.0.30319\MSBuild $(SolutionDir)\ProjectFiles\TestData\Install.msbuild
小智 5
使用
%WINDIR%\ SysNative\WindowsPowerShell\V1.0\powershell.exe
使用%WINDIR%\ SysNative的虚拟路径而不是C:\ Windows\System32的实际路径非常重要.原因是Visual Studio 2010是一个32位应用程序,需要调用64位版本的powershell.exe才能成功加载Microsoft.SharePoint.Powershell管理单元.
(c)"Microsoft SharePoint 2010内部",Microsoft Press,2011年3月
Visual Studio 是一个 32 位应用程序,因此在 64 位 Windows 中它在模拟的 32 位环境中运行。
奇怪的是,32 位环境被称为“WoW64”(当 32 位 Windows 对 16 位应用程序执行此操作时,它被称为“WoW16”。“WoW”部分的意思是“Windows on Windows”。
同样奇怪的是,“System32”在 64 位 Windows 中没有变成“System64”。“32”来自 16 位 -> 32 位转换,以区别于“System”。不管怎样,这对你来说是遗产/兼容性。
在 WoW64 中,一切看起来都像 32 位 Windows。
例如,c:\windows\system32仅指向c:\windows\syswow64. 32 位应用程序无法(轻松)实现 64 位应用程序的任何功能。
可以使用PowerShell Remoting从 32 位环境获取 64 位 PowerShell 会话。
PS>gci 环境:PROCESSOR_ARCH*
名称 值
---- -----
处理器_架构 x86
PROCESSOR_ARCHITEW6432 AMD64
PS>Invoke-Command -ConfigurationName Microsoft.PowerShell -ComputerName LOCALHOST { gci env:PROCESSOR_ARCH* }
名称 值 PSComputerName
---- ----- --------------
PROCESSOR_ARCHITECTURE AMD64 本地主机
| 归档时间: |
|
| 查看次数: |
2616 次 |
| 最近记录: |