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

     } 

它拋出異常:運行PowerShell命令

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

任何建議,爲什麼?

+0

您是否找到任何解決方案? – 2016-03-31 07:14:53

回答

10

添加該命令先:

Add-PSSnapin Microsoft.SharePoint.Powershell -EA 0

-1

另外,還要確保你從運行在IIS上的Web應用程序運行「Add-SPSolution」命令,而不是使用標準的Visual Studio se運行rver(當你按下F5時)。

2

我最近有這個問題。就我而言,我無法看到增加的解決方案,也無法添加解決方案。所以首先我使用下面的PowerShell命令刪除解決方案:

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

然後我能夠添加我的新代碼解決方案。