我有以下代码从桌面应用程序运行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
包含错误:
[System.Fabric.FabricObjectClosedException]
还有其他错误,但是由于未加载ServiceFabric
模块而导致错误。但是,即使没有RemoteSigned执行策略的管理员权限,此脚本也会从powershell窗口成功运行。那么有没有办法从C#运行这个脚本,所有模块都加载像Poweshell ISE一样?
答案 0 :(得分:5)
尝试将您的桌面应用程序作为x64应用程序运行。 Service Fabric SDK仅适用于x64系统。