1

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?

1
  • I am trying to run the command Copy-ServiceFabricApplicationPackage through c# but I get The term 'Copy-ServiceFabricApplicationPackage' is not recognized as the name of a cmdlet. What should be the path tmppath? Commented Oct 30, 2017 at 16:11

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, that helped, I have been struggling with it for 2 days. So it seems that powershell x86 has completely different set of modules.
Unlikely. More likely that the SF SDK was just compiled against x64.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.