在Sharepoint 2013环境中添加、部署和删除解决方案的最佳方法?

在Sharepoint 2013环境中添加、部署和删除解决方案的最佳方法?,sharepoint,powershell,sharepoint-2013,Sharepoint,Powershell,Sharepoint 2013,我们有一个插件,在安装这个插件时,我们有一个“exe”,它将在中央配置站点中添加和部署解决方案(.wsp文件)。在卸载插件时,exe将停用与插件相关的激活功能,收回解决方案并最终删除解决方案。此插件将安装在所有web前端 为了执行上述操作,我们可以使用PowerShell命令或SharePoint API(因为STSADM已被弃用,我不包括这一点) 我可以知道最好的方法吗?以下是我的一些观察结果 PowerShell命令: 在这方面也有两种方法 将PowerShell命令传递给System.Di

我们有一个插件,在安装这个插件时,我们有一个“exe”,它将在中央配置站点中添加和部署解决方案(.wsp文件)。在卸载插件时,exe将停用与插件相关的激活功能,收回解决方案并最终删除解决方案。此插件将安装在所有web前端

为了执行上述操作,我们可以使用PowerShell命令或SharePoint API(因为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()
    

    ProcessStartInfo pInfo=new ProcessStartInfo(“,”您不需要EXE来运行PowerShell脚本。只需将脚本保存在文件(例如MyScript.ps1)中,并在SharePoint PowerShell控制台中运行即可。如上面的评论所示,您可以调用SharePoint cmdlet(例如添加SPSolution)从脚本部署WSP并激活功能


    将此逻辑打包到EXE会增加实现的复杂性,使部署的故障排除变得复杂,因此不应将其视为最佳做法。

    我不确定您为什么要执行所有运行空间操作和processstartinfo。
    添加SPSolution
    /
    安装SPSolution
    Powershell有什么问题commandlets?还有许多WSP部署脚本,最著名的是codeplex上的SharePoint解决方案部署程序。您好,感谢您的评论。我正在ProcessStartInfo API中调用相同的powershell命令。这是使用exe运行命令。然后您已经得到了答案。最佳做法是完全使用这些逗号nds。请查看可用的PowerShell脚本以完成部署,但它背后没有任何魔力。我想实现自动化,基本上是在我们运行exe时,它应该将解决方案添加并部署到管理中心站点。截至目前,我正在使用ProcessStart API来运行PowerShell脚本文件,因为与其他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>();