【发布时间】:2020-07-17 16:37:28
【问题描述】:
我需要帮助来解决将 .Net Core Web 应用程序 Api 自动部署到服务器的问题。
如您所知,如果您之前不停止AppPool,则不可能覆盖.dll,并且IIS 中没有解决方案。
实际上通过使用PowerShell 我可以执行一个脚本来做我需要的脚本如下所示:
PowerShell script
实际上我需要一个控制台应用程序来执行相同的工作,我发现我可以使用Microsoft.PowerShell.SDK 来实现一个解决方案。
public static void RunC()
{
string us = "xxxxxxxxxxxxx"; //User
string pw = "xxxxxxxxxxxxxxxx";//Passwprd
string sv = "xxx.x.xx.xxx";//Server
string apppoolname = "xxxxxxxxxxxxx";
StringBuilder script = new StringBuilder();
//Creazione script PS
script.Append("$password = ConvertTo-SecureString \"" + pw + "\" -AsPlainText -Force" + Environment.NewLine);
script.Append("$user = \"" + us + "\"" + Environment.NewLine);
script.Append("$cred = New-Object System.Management.Automation.PSCredential ($user,$password)" + Environment.NewLine);
script.Append("Enter-PSSession -ComputerName \"" + sv + "\" -Credential $cred" + Environment.NewLine);
script.Append("Import-Module webadministration");
script.Append("Stop-WebAppPool \"" + apppoolname + "\"");
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(script.ToString());
//pipeline.Commands.Add("Out-String");
Collection<PSObject> results = pipeline.Invoke();
StringBuilder sb = new StringBuilder();
foreach (PSObject pSObject in results)
{
sb.AppendLine(pSObject.ToString());
}
Console.WriteLine(sb.ToString());
}
但我在图像中显示错误,接缝模块未加载或类似的东西.. 有人可以以某种方式帮助我吗?
谢谢你:-)
【问题讨论】:
标签: c# powershell .net-core winrm