F# 运行 Powershell 脚本作为目标

F# Run Powershell Script As Target

正在尝试 运行 使用 F# FAKE 的 powershell 脚本但没有任何反应...没有错误,目标已加载但实际上什么都没有 运行。

// include Fake lib
#r "packages/FAKE/tools/FakeLib.dll"
#r "System.Management.Automation"

open System
open System.IO
open System.Diagnostics
open System.Management.Automation

    Target "Powershell" <| fun _ ->
    PowerShell.Create()
      .AddScript("& 'build-database.ps1'")
      .AddParameter("BuildVersion", version)
      .AddParameter("Debug", "")
      .Invoke()
      |> Seq.iter (printfn "%O")

// Dependencies
"Clean"
  ==> "Powershell"

// start build
RunTargetOrDefault "Powershell"

我错过了什么吗?没有任何错误,我不确定问题是什么。

* 已更新 *

这是我正在测试的 powershell 脚本,FAKE 什么都不做。

New-Item c:\AnEmptyFile.txt -ItemType file

我终于找到了另一种可行的方法。如果其他人需要从 F# FAKE 中调用 powershell 脚本,以下方法对我有用。

Target "Powershell" (fun _ ->

        let p = new System.Diagnostics.Process();              
        p.StartInfo.FileName <- "cmd.exe";
        p.StartInfo.Arguments <- ("/c powershell -ExecutionPolicy Unrestricted .\script.ps1)
        p.StartInfo.RedirectStandardOutput <- true
        p.StartInfo.UseShellExecute <- false
        p.Start() |> ignore

        printfn "Processing..."
        printfn "%A" (p.StandardOutput.ReadToEnd())
        printfn "Finished"
)

可以使用 Shell.Execute 并调用 powershell.exe:

Target "ImportDb" (fun _ ->
    Shell.Exec("powershell.exe", "-NoProfile -ExecutionPolicy Bypass -File script.ps1") |> ignore)