简体   繁体   中英

Running service fabric powershell scripts from C#

I have the following code to run powershell script (standard Deploy-FabricApplication.ps1 shipped with Service Fabric project template) from desktop app:

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();
}

However shell contains error after script invocation:

  • The specified module 'ServiceFabric' was not loaded because no valid module file was found in any module directory.
  • Unable to find type [System.Fabric.FabricObjectClosedException]

There are another errors, but they caused because ServiceFabric module wasn't loaded. But this script runs successfully from powershell window, even without admin privileges with RemoteSigned execution policy. So is there any way to run this script from C# with all modules loaded like in Poweshell ISE?

Try running your desktop app as an x64 application. The Service Fabric SDK is only available for x64 systems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM