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