【发布时间】:2017-08-17 21:07:45
【问题描述】:
我有以下代码可以从桌面应用程序运行 powershell 脚本(Service Fabric 项目模板附带的标准 Deploy-FabricApplication.ps1):
using (var shell = PowerShell.Create())
{
Environment.CurrentDirectory = tmpPath;
var deploymentScriptPath = Path.Combine(tmpPath, "Scripts", "Deploy-FabricApplication.ps1");
var command = new Command(deploymentScriptPath);
shell.AddScript("Import-Module ServiceFabric");
command.Parameters.Add("PublishProfileFile", Path.Combine(tmpPath, "PublishProfiles\\Local.5Node.xml"));
command.Parameters.Add("ApplicationPackagePath", Path.Combine(tmpPath, "pkg\\Release"));
shell.Commands.AddCommand(command);
shell.Invoke();
}
但是shell 在脚本调用后包含错误:
- 未加载指定的模块“ServiceFabric”,因为没有有效的 在任何模块目录中都找到了模块文件。
- 找不到类型
[System.Fabric.FabricObjectClosedException]
还有另一个错误,但它们是因为未加载 ServiceFabric 模块而引起的。但是,即使没有使用 RemoteSigned 执行策略的管理员权限,此脚本也可以从 powershell 窗口成功运行。那么有没有办法从 C# 运行这个脚本,并且像在 Poweshell ISE 中一样加载所有模块?
【问题讨论】:
-
我正在尝试通过 c# 运行命令 Copy-ServiceFabricApplicationPackage,但我得到“Copy-ServiceFabricApplicationPackage”一词未被识别为 cmdlet 的名称。路径 tmppath 应该是什么?
标签: c# powershell azure-service-fabric