gpt4 book ai didi

c# - 是否可以从 Cake 任务中调用 powershell 命令

转载 作者:行者123 更新时间:2023-11-30 21:37:08 25 4
gpt4 key购买 nike

我正在从 Psake 构建工具切换到 Cake ( https://cakebuild.net/ )。我正在为具有(当前)9 种不同部署的相当大的解决方案(30 多个项目)创建脚本。在 Psake 中调用 PowerShell 命令很简单,因为整个脚本都在 powershell 中运行。

但是现在我遇到了一个问题。我不得不调用一些在PS中运行的命令,但我找不到执行它们的方法。

一些例子:

taskkill /IM iisexpress.exe
Invoke-Command -ComputerName <testing server> -ScriptBlock {import-module WebAdministration; Stop-Website <'name of website'>}
Invoke-Command -ComputerName <testing server> -ScriptBlock {import-module WebAdministration; Start-Website <'name of website'>}

我已尝试使用 StartAndReturnProcess(示例:StartAndReturnProcess("taskkill/IM iisexpress.exe");),但没有成功。我还找到了 Cake.IIS 插件,它可能会解决我启动和停止 IIS 的问题,但还有一些我想调用的其他 PS 命令。

是否可以从 Task 中简单地调用 PowerShell 命令?像这样:

Task("DoSomeMagic")
.Does(() =>
{

ExecutePowerShellCommad("taskkill /IM iisexpress.exe");
ExecutePowerShellCommad("Invoke-Command -ComputerName <testing server> -ScriptBlock {import-module WebAdministration; Stop-Website <'name of website'>}");

//ToDo: other magic
});

感谢您的回答和最诚挚的问候,马丁

最佳答案

你见过Cake.PowerShell吗?插件?

可以找到示例用法 here ,但提供一个示例(取自自述文件):

#addin "Cake.Powershell"

Task("Powershell-Script")
.Description("Run an example powershell command with parameters")
.Does(() =>
{
StartPowershellScript("Write-Host", args =>
{
args.AppendQuoted("Testing...");
});
});

自述文件中有更复杂的示例,具体取决于您要实现的目标。

关于c# - 是否可以从 Cake 任务中调用 powershell 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47515919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com