我只是在处理MSDeploy的C#API(Microsoft.Web.Deployment.dll),但我正在努力寻找一种方法来确定依赖关系对于给定的Web服务器。使用MSDeploy API获取Web服务器的依赖关系
基本上,我想在C#相当于以下MSDeploy命令行调用的:
msdeploy.exe -verb:getDependencies -source:webServer
我试过the documentation,但我没有运气。任何人都可以指引我走向正确的方向吗?
我只是在处理MSDeploy的C#API(Microsoft.Web.Deployment.dll),但我正在努力寻找一种方法来确定依赖关系对于给定的Web服务器。使用MSDeploy API获取Web服务器的依赖关系
基本上,我想在C#相当于以下MSDeploy命令行调用的:
msdeploy.exe -verb:getDependencies -source:webServer
我试过the documentation,但我没有运气。任何人都可以指引我走向正确的方向吗?
检查了Reflector中的MSDeploy可执行文件后,似乎getDependencies操作没有被API公开(方法是内部的)。
所以不是我不得不退到呼唤命令行和处理结果:
static void Main()
{
var processStartInfo = new ProcessStartInfo("msdeploy.exe")
{
RedirectStandardOutput = true,
Arguments = "-verb:getDependencies -source:webServer -xml",
UseShellExecute = false
};
var process = new Process {StartInfo = processStartInfo};
process.Start();
var outputString = process.StandardOutput.ReadToEnd();
var dependencies = ParseGetDependenciesOutput(outputString);
}
public static GetDependenciesOutput ParseGetDependenciesOutput(string outputString)
{
var doc = XDocument.Parse(outputString);
var dependencyInfo = doc.Descendants().Single(x => x.Name == "dependencyInfo");
var result = new GetDependenciesOutput
{
Dependencies = dependencyInfo.Descendants().Where(descendant => descendant.Name == "dependency"),
AppPoolsInUse = dependencyInfo.Descendants().Where(descendant => descendant.Name == "apppoolInUse"),
NativeModules = dependencyInfo.Descendants().Where(descendant => descendant.Name == "nativeModule"),
ManagedTypes = dependencyInfo.Descendants().Where(descendant => descendant.Name == "managedType")
};
return result;
}
public class GetDependenciesOutput
{
public IEnumerable<XElement> Dependencies;
public IEnumerable<XElement> AppPoolsInUse;
public IEnumerable<XElement> NativeModules;
public IEnumerable<XElement> ManagedTypes;
}
希望这是对别人有用的不断试图做同样的事情!
实际上有一种通过公共API通过使用DeploymentObject.Invoke(string methodName,params object [] parameters)。
当 “getDependencies” 用于方法名,该方法返回一个的XPathNavigator对象:
DeploymentObject deplObj = DeploymentManager.CreateObject(DeploymentWellKnownProvider.WebServer, String.Empty);
var result = deplObj.Invoke("getDependencies") as XPathNavigator;
var xml = XDocument.Parse(result.InnerXml);