问题是我没有收到任何错误,但我得到一个加载屏幕,显示PowerShell成功调用的内容,但所有内容都被暂停(没有失败,它只是与Windows PowerShell [copyright info]
徘徊。在挖掘中,我决定只是看看我是否可以写出警告,看来它正在将执行策略设置为不受限制(这也是我的系统当前设置的方式)。
我确实认为执行政策可能没有设置为不受限制,因此我尝试传递-Force
参数,但收到错误信息是无效的。
PS脚本:
Write-Warning "Called successfully.
要调用它的XML代码:
<Target Name="DoSomething">
<PropertyGroup>
<ponyone>FullOne</ponyone>
<ponytwo>HalfOne</ponytwo>
<ponytree>LatterExcen</ponytree>
</PropertyGroup>
<Exec Command="powershell.exe -NonInteractive -executionpolicy Unrestricted" />
<Exec Command="powershell.exe .\Do-Something.ps1 FullOne HalfOne LatterExcen" />
</Target>
确认这是因为executionpolicy;当我只运行第二个脚本时,由于脚本被禁用而导致错误,即使PowerShell显示执行策略不受限制。
答案 0 :(得分:1)
使用以下msbuild项目:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
<Target Name="RunPSScript">
<Exec Command="powershell.exe -NonInteractive -executionpolicy Unrestricted -command ".\Do-Something.ps1""/>
</Target>
</Project>
PS脚本按预期执行,给出以下输出:
Microsoft (R) Build Engine version 14.0.25123.0
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 5/25/2016 1:43:41 PM.
Project "D:\lab\my.proj" on node 1 (default targets).
RunPSScript:
powershell.exe -NonInteractive -executionpolicy Unrestricted -command ".\Do-Something.ps1"
EXEC : warning : Called successfully. [D:\lab\my.proj]
Done Building Project "D:\lab\my.proj" (default targets).
Build succeeded.
"D:\lab\my.proj" (default target) (1) ->
(RunPSScript target) ->
EXEC : warning : Called successfully. [D:\lab\my.proj]
1 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.36
更多详情here。