我只是想了解MSDeploy的C#API(Microsoft.Web.Deployment.dll),但是我正在努力寻找一种确定给定Web服务器依赖性的方法。
基本上,我希望使用等效于以下MSDeploy命令行调用的C#:
msdeploy.exe -verb:getDependencies -source:webServer
Run Code Online (Sandbox Code Playgroud)
我已经尝试过文档,但是没有运气。有人能指出我正确的方向吗?
在Reflector中检查了MSDeploy可执行文件之后,API似乎没有公开getDependencies操作(该方法是内部的)。
因此,我不得不依靠命令行来处理结果:
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;
}
Run Code Online (Sandbox Code Playgroud)
希望这对尝试做同一件事的其他人有用!