我试图让 Powershell 在构建后运行我的 PS 脚本 - 但不知怎的,它并没有像预期的那样工作:
在构建后执行以下命令:
C:\WINDOWS\system32\windowspowershell\1.0\powershell.exe
-Command "& $(MSBuildProjectDirectory)\CreateSite.ps1 'auto'"
(插入换行符以便更好阅读)
该命令成功执行了 powershell 脚本,但它无法运行(Build 的输出)中的命令:
运行构建后命令:
Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2
At C:\path\CreateSite.ps1:4 char:
38
+ Add-PsSnapin <<<< Microsoft.SharePoint.PowerShell}
+ CategoryInfo : InvalidArgument: (Microsoft.SharePoint.PowerShell:String) [Add-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
接下来是许多错误,因为所有后续命令都需要 Sharepoint 管理单元。
- 从 cmd 运行 powershell C:\path\CreateSite.ps1 auto 时 - 一切正常。
- 打开 powershell.exe 并运行 C:\path\CreateSite.ps1 auto 时 - 一切正常。
- 当右键单击 CreateSite.ps1 --> 使用 powershell 运行时 - 一切正常。
脚本中的相关行很简单Add-PsSnapin Microsoft.SharePoint.PowerShell
.
我怎样才能运行这个该死的脚本(并让它包含 PSSnapIn)并在 Visual Studio 构建后向它传递一个参数?
(这个线程并不新鲜,但我从谷歌来到这里,所以我认为分享我发现的解决方案对其他人来说会很有趣)
我尝试将 powershell.exe 的路径更改为“%WINDIR%\SysNative\WindowsPowerShell\v1.0\powershell.exe”,效果完美。从构建后事件调用 64 位版本,并成功添加 SharePoint 管理单元。
本文来源:http://msdn.microsoft.com/en-us/library/ff798298.aspx,“在 Visual Studio 中使用 Windows PowerShell 脚本自动执行任务”。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)