【问题标题】:MSBuild Call PS Script - Does NothingMSBuild 调用 PS 脚本 - 什么都不做
【发布时间】:2016-05-24 16:19:36
【问题描述】:

问题是我没有收到任何错误,但我得到了一个加载屏幕,显示似乎成功调用了 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>

确认这是因为执行政策;当我只运行第二个脚本时,由于脚本被禁用,它会出错,即使 PowerShell 显示执行策略不受限制。

【问题讨论】:

  • 您的问题是什么?您显示的两个调用中哪一个有问题?

标签: powershell msbuild


【解决方案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 &quot;.\Do-Something.ps1&quot;"/>  
    </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.

【讨论】:

    猜你喜欢
    • 2014-08-28
    • 2018-10-09
    • 2023-01-30
    • 1970-01-01
    • 1970-01-01
    • 2012-05-17
    • 1970-01-01
    • 2018-05-25
    • 2018-11-08
    相关资源
    最近更新 更多