2010-06-12 26 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 
      } 

     } 

es tirar la excepción:comandos de ejecución de 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. 

Cualquier sugerencia por qué?

+0

¿encontró alguna solución? –

Respuesta

10

Añadir este comando primero:

Add-PSSnapin Microsoft.SharePoint.Powershell -EA 0

-1

También asegúrese de que está ejecutar el comando "Add-SPSolution" desde las aplicaciones web, que se ejecuta en IIS, y NO con el estándar de Visual Studio rver (cuando presiona F5).

2

Tengo este problema recientemente. En mi caso, no pude ver la solución agregada ni pude agregar una solución. Así que primero elimino la solución usando el comando PowerShell siguiente:

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

Luego pude agregar mi nueva solución de código.

Cuestiones relacionadas