public MSBuildScriptParser(string fileName) { var file = new XmlDocument(); file.Load(fileName); if (file.DocumentElement == null || file.DocumentElement.Name != "Project") { throw new ArgumentException("this is not a csproj/vbproj file", "fileName"); } string attribute = file.DocumentElement.GetAttribute("ToolsVersion"); if (string.IsNullOrEmpty(attribute)) { _version = Tool.Tool20Version; } else { var element = LaunchPadSection.GetSection().ScriptToolMappings[attribute]; if (element == null) { throw new ArgumentException("this is not a csproj/vbproj file", "fileName"); } _version = element.Tool; } }
private static string ParseVersion(XmlDocument file) { string attribute = file.DocumentElement.GetAttribute("ToolsVersion"); if (string.IsNullOrEmpty(attribute)) { return(Tool.Tool20Version); } else { var element = LaunchPadSection.GetSection().ScriptToolMappings[attribute]; if (element == null) { throw new ArgumentException("this is not a proj file", "fileName"); } return(element.Tool); } }
public SolutionParser(string fileName) { string content = File.ReadAllText(fileName); Match match = Regex.Match(content); if (!match.Success) { throw new ArgumentException("this is not a sln file", "fileName"); } var fileVersion = match.Groups[1].Value; var versionFound = VersionDetector.Match(content); var key = string.Format("{0}|{1}", fileVersion, versionFound.Success ? versionFound.Groups["version"].Value : "*"); var toolVersion = LaunchPadSection.GetSection().SolutionFileMappings[key]; if (toolVersion == null) { throw new ArgumentException(string.Format("this file is not a sln file we support. Key: {0}", key), "fileName"); } _version = toolVersion.Tool; }