I'm just getting to grips with the C# API for MSDeploy (Microsoft.Web.Deployment.dll), but I'm struggling to find a way that I can determine the dependencies for a given web server.
Basically, I'd like the C# equivalent of the following MSDeploy command line call:
msd开发者_运维技巧eploy.exe -verb:getDependencies -source:webServer
I've tried the documentation, but I've had no luck. Can anybody point me in the right direction?
Having examined the MSDeploy executable in Reflector, it seems that the getDependencies operation is not exposed by the API (the method is internal).
So instead I've had to fall back on calling out to the command line, and processing the results:
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;
}
Hopefully this is useful to anybody else that ever tries to do the same thing!
There actually is a way of getting there via the public API by using DeploymentObject.Invoke(string methodName, params object[] parameters).
When "getDependencies" is used for methodName, the method returns an XPathNavigator object:
DeploymentObject deplObj = DeploymentManager.CreateObject(DeploymentWellKnownProvider.WebServer, String.Empty);
var result = deplObj.Invoke("getDependencies") as XPathNavigator;
var xml = XDocument.Parse(result.InnerXml);
精彩评论