运行 来自 C# 的服务结构 powershell 脚本
Running service fabric powershell scripts from C#
我从桌面应用程序 运行 powershell 脚本(标准 Deploy-FabricApplication.ps1
附带 Service Fabric 项目模板)的代码如下:
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
模块未加载引起的。但是这个脚本 运行 成功地从 powershell window,即使没有使用 RemoteSigned 执行策略的管理员权限。那么有什么方法可以从 C# 运行 这个脚本中加载所有模块,就像在 Poweshell ISE 中一样?
尝试 运行 您的桌面应用程序作为 x64 应用程序。 Service Fabric SDK 仅适用于 x64 系统。
我从桌面应用程序 运行 powershell 脚本(标准 Deploy-FabricApplication.ps1
附带 Service Fabric 项目模板)的代码如下:
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
模块未加载引起的。但是这个脚本 运行 成功地从 powershell window,即使没有使用 RemoteSigned 执行策略的管理员权限。那么有什么方法可以从 C# 运行 这个脚本中加载所有模块,就像在 Poweshell ISE 中一样?
尝试 运行 您的桌面应用程序作为 x64 应用程序。 Service Fabric SDK 仅适用于 x64 系统。