powershell - F# 将 Powershell 脚本作为目标运行

标签 powershell f# f#-fake

尝试使用 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"
)

关于powershell - F# 将 Powershell 脚本作为目标运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34006281/

相关文章:

powershell - 将 Powershell 创建的文件的编码更改为 UTF8 而不是 UCS-2 LE

c# - 在 GPU 上运行 MSIL

f# - 如何在 Prop 更改时取消 Cmd.OfAsync?

f# - 为什么有些 FAKE 方法在目标函数中不起作用?

powershell - 如何删除文件夹中除只读文件外的所有文件?

c# - 在C#中按名称访问PSObject属性

PowerShell 和 ActiveDirectory 模块 - 查找不是特定组成员的用户

使用类型约束的 F# 模式匹配

f# - 伪造的 dotCover

f# - 如何从 VS Code 启动 F# 控制台应用程序