2010-06-12 6 views
11
RunspaceConfiguration psConfig = RunspaceConfiguration.Create(); 
Runspace psRunspace = RunspaceFactory.CreateRunspace(psConfig); 
psRunspace.Open(); 
using (Pipeline psPipeline = psRunspace.CreatePipeline()) 
      { 

      // Define the command to be executed in this pipeline 
      Command command = new Command("Add-spsolution"); 

      // Add a parameter to this command 
      command.Parameters.Add("literalpath", @"c:\project3.wsp"); 

      // Add this command to the pipeline 
      psPipeline.Commands.Add(command); 


       // Invoke the cmdlet 
      try 
      { 
       Collection<PSObject> results = psPipeline.Invoke(); 
       Label1.Text = "hi"+results.ToString(); 
       // Process the results 
      } 
      catch (Exception exception) 
      { 
       Label1.Text = exception.ToString();// Process the exception here 
      } 

     } 

Il jette l'exception:commandes Run PowerShell en C#

System.Management.Automation.CommandNotFoundException: The term 'add-spsolution' is not recognized as the name of a cmdlet, function, script file, or operable program. 

Toutes les suggestions pourquoi?

+0

Avez-vous trouvé une solution? –

Répondre

10

Ajouter cette première commande:

Add-PSSnapin Microsoft.SharePoint.Powershell -EA 0

-1

Assurez-vous également que vous êtes exécution de la commande "Add-SPSolution" à partir des applications Web, qui s'exécute sur IIS et PAS avec Visual Studio standard Rver (quand vous appuyez sur F5).

2

J'ai ce problème récemment. Dans mon cas, je n'étais ni capable de voir la solution ajoutée ni capable d'ajouter une solution. Alors d'abord je supprimer la solution à l'aide ci-dessous PowerShell Commande:

(Get-SPSolution -Identity "YourSolution.wsp").Delete() 

Alors j'ai pu ajouter ma nouvelle solution de code.

Questions connexes