gpt4 book ai didi

作为 Visual Studio 部署后命令运行时,SharePoint 脚本失败

转载 作者:行者123 更新时间:2023-12-04 00:54:22 26 4
gpt4 key购买 nike

我编写了一个脚本,将一些测试数据插入到文档库中。我打算将其用作 Visual Studio 2010 中的部署后步骤,以便在撤回和部署后库不为空。

脚本的相关部分是:

安装.ps1:

$scriptDirectory = Split-Path -Path $script:MyInvocation.MyCommand.Path -Parent
. "$scriptDirectory\Include.ps1"

$webUrl = "http://localhost/the_site_name"
$web = Get-SPWeb($webUrl)
...

包含.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);

...
}

从命令行按如下方式运行时它工作正常,甚至在重新部署 Visual Studio 后立即运行:
powershell \source\ProjectFiles\TestData\Install.ps1

However, it does not work when I use the exact same command as a post-deployment command line in the SharePoint project's properties in Visual Studio:

Run Post-Deployment Command:New-Object : Exception calling ".ctor" with "1" argument(s): "The Web application at http://localhost/the_site_name could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application."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

Interestingly, I can reproduce the error on the command line if I run:

c:\windows\Syswow64\WindowsPowerShell\v1.0\powershell \source\ProjectFiles\TestData\Install.ps1

However, the post-deployment command fails even if I explicitly run \windows\System32\WindowsPowerShell\v1.0\powershell and \windows\Syswow64\WindowsPowerShell\v1.0\powershell.

Update: Solution found

I seem to be having a similar problem to the one discussed here:

http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/faa25866-330b-4e60-8eee-bd72dc9fa5be

I cannot access a 64-bit SharePoint API using 32-bit clients. Because Visual Studio is 32-bit, the post-deployment action will run in a 32-bit process and will fail. There is, however, a 64-bit MSBuild. If we let it run the PowerShell script, all is fine.

Wrap the script in an MSBuild file such as this:

<?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>

然后,将部署后命令行设置为:

%WinDir%\Microsoft.NET\Framework64\v4.0.30319\MSBuild $(SolutionDir)\ProjectFiles\TestData\Install.msbuild

最佳答案



%WINDIR%\SysNative\WindowsPowerShell\v1.0\powershell.exe

使用 %WINDIR%\SysNative 的虚拟路径而不是实际路径很重要
C:\Windows\System32 的路径。这样做的原因是 Visual Studio 2010 是一个 32 位的
需要调用 64 位版本的 powershell.exe 才能成功加载的应用程序
Microsoft.SharePoint.Powershell 管理单元。

(c)“Inside Microsoft SharePoint 2010”,微软出版社,2011 年 3 月

关于作为 Visual Studio 部署后命令运行时,SharePoint 脚本失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3913498/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com