我只是在處理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);