public string GetOutputDirectory(string projectFilePath, string config) { string OutputValue; XmlDocument xd = new XmlDocument(); xd.PreserveWhitespace = true; xd.Load(projectFilePath); string NameSpaceFor2005 = @"http://schemas.microsoft.com/developer/msbuild/2003"; bool Is2005 = xd.DocumentElement.HasAttribute("xmlns"); if (Is2005) { XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xd.NameTable); namespaceManager.AddNamespace("b", NameSpaceFor2005); XmlNode Node = null; Node = xd.SelectSingleNode(string.Format("//b:PropertyGroup[contains(@Condition, '{0}')]/b:OutputPath", config), namespaceManager); if (Node == null) { return(null); } OutputValue = Node.InnerText; OutputValue = OutputValue.TrimEnd(@"\".ToCharArray()); } else { XmlNode Node = null; Node = xd.SelectSingleNode(string.Format("//Config[@Name = '{0}']/@OutputPath", config)); if (Node == null) { return(null); } OutputValue = Node.InnerText; OutputValue = OutputValue.TrimEnd(@"\".ToCharArray()); } if (Path.IsPathRooted(OutputValue)) { return(Path.GetFullPath(OutputValue)); } return(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(projectFilePath), OutputValue))); }