我们有一个插件,在安装此插件时,我们有一个“exe”,它将在中央配置站点中添加和部署解决方案(.wsp文件)。在取消安装插件时,exe将停用与我们的插件相关的激活功能,收回解决方案并最终删除解决方案。该插件将安装在所有Web前端。
为了执行上述操作,我们可以使用PowerShell命令或SharePoint APIS(因为不推荐使用STSADM,我不包括它)。
我可以知道最好的方法吗?以下是我的一些观察
PowerShell命令:
这也有两种方法
将PowerShell命令传递给System.Diagnostics.Process
ProcessStartInfo pInfo = new ProcessStartInfo("<PowerShellExePath>", "<ScriptToExecute or Powershell File Name");
Process process = new Process();
process.StartInfo = pInfo;
process.Start()
Runspace API
Runspace runspace = RunspaceFactory.CreateRunspace(InitialSessionState.CreateDefault());
runspace.Open();
PowerShell powerShellCommand = PowerShell.Create();
powerShellCommand.Runspace = runspace;
powerShellCommand.AddScript("Add-PsSnapin Microsoft.SharePoint.PowerShell");
powerShellCommand.AddScript(script);
powerShellCommand.Invoke<string>();
SharePoint API
Microsoft.SharePoint.Administration.SPFarm.Local.Solutions.Add或Microsoft.SharePoint.Administration.SPFarm.Local.Solutions.Remove。
谢谢&amp;的问候,
卡莱。
答案 0 :(得分:0)
您不需要EXE来运行PowerShell脚本。只需将脚本保存在文件(例如MyScript.ps1)中,然后在SharePoint PowerShell控制台中运行它。如上面的注释所示,您可以从脚本调用SharePoint cmdlet(例如Add-SPSolution)来部署WSP并激活功能。
将此逻辑打包到EXE会增加实施的复杂性,使部署的故障排除变得复杂,因此不应被视为最佳实践。