2

Im trying to run jss cli commands (Windows Powershell) from my C# Class. I`m creating the commands dynamically, but i noticed that jss commands are not running.

            PowerShell ps = PowerShell.Create();

            //Call Powershell
            foreach (var item in scripts)
            {
                ps.AddScript(item);
            }
            Collection<PSObject> results = ps.Invoke();

This is the code to create the scripts dynamically:

             //Name of Component
             var nameofComponent = definitonArchive.Name.Replace(".sitecore.js", "");
             var locationSystem = Sitecore.Configuration.Settings.GetSetting("X:JSSApplicationFolder");

             //Add location command
             PowerShellCommands.Add($"Set-Location -Path {locationSystem}");

             //Create the JSS manifest command
             var jssManifestCommand = String.Format("jss manifest --manifestSourceFiles '{0}'", definitonArchive.FullName.Replace("/", @"\"));
             PowerShellCommands.Add($"Invoke-Expression \"{jssManifestCommand}\"");


             //Add build command
             var jssDeployCommand = "jss deploy app --includeContent --includeDictionary";
             PowerShellCommands.Add($"Invoke-Expression \"{jssDeployCommand}\"");

I noticed that nothing was happening, however using a console application with the same logic, everything works fine.

I created another command just to create a txt file, in purpose to test, and works fine.

              //To test
              PowerShellCommands.Add(@"New-Item C:\temp\test.txt");

I also created a log to check if the scripts are with a correct syntax, and they are good.

I noticed the error i`m receiving is:

The term 'jss' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

7
  • How are you running the C# class? Commented Jun 10, 2020 at 19:07
  • @HishaamNamooya Web project. I call an API from my view using Ajax and my API call the Service that contains these logics. Commented Jun 11, 2020 at 19:00
  • I’m trying to replicate the issue but i cannot get passed by the powershell library. I mean i cannot see the system.management.automation assembly. Can please provide more details on this or share the nuget package Commented Jun 11, 2020 at 19:35
  • @HishaamNamooya I noticed that the error that Im receiving is: The term 'jss' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. Its weird because if I run the same command that Im running but manually, works perfectly. Commented Jun 11, 2020 at 19:52
  • Is the jss command installed globally? Commented Jun 11, 2020 at 20:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.