Mar*_*pus 6 c# powershell cakebuild
我正在从 Psake 构建工具切换到 Cake ( https://cakebuild.net/ )。我正在为相当大的解决方案(30 多个项目)创建一个脚本,其中(目前)有 9 个不同的部署。在 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'>}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过 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
});
Run Code Online (Sandbox Code Playgroud)
感谢任何答案和最好的问候,马丁
你见过Cake.PowerShell插件吗?
示例用法可以在这里找到,但要提供一个示例(取自自述文件):
#addin "Cake.Powershell"
Task("Powershell-Script")
.Description("Run an example powershell command with parameters")
.Does(() =>
{
StartPowershellScript("Write-Host", args =>
{
args.AppendQuoted("Testing...");
});
});
Run Code Online (Sandbox Code Playgroud)
自述文件中有更复杂的示例,具体取决于您要实现的目标。
| 归档时间: |
|
| 查看次数: |
3310 次 |
| 最近记录: |