// Assumption: filename already exists and is already verified to be a file public static void LoadFile(MetabuildProject metabuild, String filename) { Console.WriteLine("[DEBUG] Metabuild.LoadFile \"{0}\"", filename); String relativeDir = null; using (LfdTextReader reader = new LfdTextReader(new StreamReader(new FileStream( filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))) { LfdParser parser = new LfdParser(reader, filename); LfdLine line = parser.reader.ReadLineIgnoreComments(); for (; ;) { if (line == null) { return; } if (line.id == "Import") { parser.errors.EnforceFieldCount(line, 1); MetabuildUnit.LoadDirOrFile(metabuild, line.fields[0]); line = parser.reader.ReadLineIgnoreComments(); } else if (line.id == "CSharpProject") { if (relativeDir == null) { relativeDir = Path.GetDirectoryName(filename); } line = CSharpProject.Parse(metabuild, parser, line, false, relativeDir); } else if (line.id == "CSharpTestProject") { if (relativeDir == null) { relativeDir = Path.GetDirectoryName(filename); } line = CSharpProject.Parse(metabuild, parser, line, true, relativeDir); } else if (line.id == "GeneratePathPrefix") { parser.errors.EnforceFieldCount(line, 1); if (metabuild.generatePathPrefix != null) { throw parser.errors.Error(line, "GeneratePathPrefix was set more than once"); } metabuild.generatePathPrefix = line.fields[0]; line = parser.reader.ReadLineIgnoreComments(); } else { throw parser.errors.Error(line, "unknown directive '{0}'", line.id); } } } }
public static ProjectConfiguration Show(string filename) { var ext = Path.GetExtension(filename); BaseVsProject vsProject = null; switch (ext.ToLower()) { case ".vcproj": vsProject = VcProject.Parse(filename); break; case ".csproj": vsProject = CSharpProject.Parse(filename); break; case ".dsp": vsProject = VisualCpp6Project.Parse(filename); break; default: MessageBox.Show("Project file not recognized"); return(null); } var f = new ProjectConfigurationsForm(); foreach (var cfg in vsProject.Configurations) { var item = f.listView.Items.Add(cfg.Name); item.SubItems.Add(cfg.Platform); item.Tag = cfg; } if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK) { return(f.listView.SelectedItems[0].Tag as ProjectConfiguration); } return(null); }
public void i_can_retrieve_target_framework_version() { var project = CSharpProject.Parse(GetFile("dll.csproj.xml")); Assert.AreEqual("v4.0.3", project.TargetFrameworkVersion); }
private void ReadProjects(string file) { if (String.IsNullOrEmpty(file)) { throw new ArgumentException("file"); } string folder = System.IO.Path.GetDirectoryName(file); var cSharpProjects = new Dictionary <string, CSharpProject>(); var cppProjects = new Dictionary <string, CppProject>(); foreach (string line in File.ReadAllLines(file)) { if (line.StartsWith("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}")) { string[] items = line.Split(','); string projectName = items[0].Split('=')[1].Trim().Trim('"'); string projectPath = PathHelpers.Combine(folder, items[1].Trim().Trim('"')); if (projectPath.StartsWith("..")) { projectPath = System.IO.Path.Combine(Path, projectPath); } try { cSharpProjects.Add(projectName, CSharpProject.Parse(new FileInfo(projectPath))); } catch (Exception ex) { Trace.TraceError("parsing '" + file + "' : " + projectName + ": " + ex.Message + " (" + projectPath + ")"); cSharpProjects.Add(projectName, new CSharpProject(new FileInfo(projectPath))); } } else if (line.StartsWith("Microsoft Visual Studio Solution File")) { int start = line.IndexOf("Format Version"); if (start > 0) { Version = line.Substring(start + "Format Version".Length + 1); } } else if (line.StartsWith("Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}")) { string[] items = line.Split(','); string projectName = items[0].Split('=')[1].Trim().Trim('"'); string projectPath = PathHelpers.Combine(folder, items[1].Trim().Trim('"')); if (projectPath.StartsWith("..")) { projectPath = System.IO.Path.Combine(Path, projectPath); } try { cppProjects.Add(projectName, CppProject.Parse(new FileInfo(projectPath))); } catch (Exception ex) { Trace.TraceError("parsing '" + file + "' : " + projectName + ": " + ex.Message + " (" + projectPath + ")"); cppProjects.Add(projectName, new CppProject(new FileInfo(projectPath))); } } else { //Trace.TraceInformation("skipping line: '" + line + "'"); } } CSharpProjects = cSharpProjects; CppProjects = cppProjects; }
public ProjectAdapter ImportProject(string fileName, string sccRoot) { var filename = fileName; var ext = Path.GetExtension(filename); BaseVsProject vsProject = null; switch (ext.ToLower()) { case ".vcproj": vsProject = VcProject.Parse(filename); break; case ".csproj": vsProject = CSharpProject.Parse(filename); break; case ".dsp": vsProject = VisualCpp6Project.Parse(filename); break; default: return(null); } if (vsProject == null) { return(null); } if (!sccRoot.EndsWith("/")) { sccRoot = sccRoot + "/"; } var project = new ProjectAdapter(new Project(), false) { BuildFile = this, Name = vsProject.Name, Path = GetPathRootedAtBuildsFile(vsProject.Filepath), SccPath = sccRoot + GetPathRootedAtBuildsFile(Path.GetDirectoryName(vsProject.Filepath)).Replace("\\", "/") }; // check if project path is relative to mproj file switch (vsProject.Framework) { case ProjectFramework.VisualCpp2003: project.Framework = "vc71"; break; case ProjectFramework.VisualCpp2005: project.Framework = "vc8"; break; case ProjectFramework.VisualCpp6: project.Framework = "vc6"; break; case ProjectFramework.VisualCs2005: project.Framework = "cs"; break; case ProjectFramework.VisualCs2003: project.Framework = "vc71"; break; } bool bConfigurationFound = false; var projectOutput = new ProjectOutputAdapter(); foreach (var conf in vsProject.Configurations) { if (conf.Name.ToLower().Contains("release")) { project.BuildOpt = "\"" + conf.Name + "\" " + conf.Platform; projectOutput.PathList.Add(Path.Combine(GetPathRootedAtBuildsFile(conf.OutputPath), "*.*")); bConfigurationFound = true; project.Target.PlatformName = conf.Platform; project.Target.ConfigurationName = conf.Name; break; } } if (!bConfigurationFound) { if (vsProject.Framework == ProjectFramework.VisualCpp6) { projectOutput.PathList.Add( Path.Combine(GetPathRootedAtBuildsFile(Path.GetDirectoryName(vsProject.Filepath)), @"release\*.*")); } else { projectOutput.PathList.Add( Path.Combine(GetPathRootedAtBuildsFile(Path.GetDirectoryName(vsProject.Filepath)), "*.*")); } } project.OutputInformation.Add(projectOutput); return(project); }