static public void EvaluateProjectReferences(string ProjectPath, List <MSFBProject> evaluatedProjects, MSFBProject dependent) { if (!string.IsNullOrEmpty(ProjectPath) && File.Exists(ProjectPath)) { try { MSFBProject newProj = evaluatedProjects.Find(elem => elem.Proj.FullPath == Path.GetFullPath(ProjectPath)); if (newProj != null) { //Console.WriteLine("Found exisiting project " + Path.GetFileNameWithoutExtension(ProjectPath)); if (dependent != null) { newProj.Dependents.Add(dependent); } } else { ProjectCollection projColl = new ProjectCollection(); if (!string.IsNullOrEmpty(SolutionDir)) { projColl.SetGlobalProperty("SolutionDir", SolutionDir); } newProj = new MSFBProject(); Project proj = projColl.LoadProject(ProjectPath); if (proj != null) { proj.SetGlobalProperty("Configuration", CommandLineOptions.Config); proj.SetGlobalProperty("Platform", CommandLineOptions.Platform); if (!string.IsNullOrEmpty(SolutionDir)) { proj.SetGlobalProperty("SolutionDir", SolutionDir); } proj.ReevaluateIfNecessary(); newProj.Proj = proj; if (dependent != null) { newProj.Dependents.Add(dependent); } var ProjectReferences = proj.Items.Where(elem => elem.ItemType == "ProjectReference"); foreach (var ProjRef in ProjectReferences) { if (ProjRef.GetMetadataValue("ReferenceOutputAssembly") == "true" || ProjRef.GetMetadataValue("LinkLibraryDependencies") == "true") { //Console.WriteLine(string.Format("{0} referenced by {1}.", Path.GetFileNameWithoutExtension(ProjRef.EvaluatedInclude), Path.GetFileNameWithoutExtension(proj.FullPath))); EvaluateProjectReferences(Path.GetDirectoryName(proj.FullPath) + Path.DirectorySeparatorChar + ProjRef.EvaluatedInclude, evaluatedProjects, newProj); } } //Console.WriteLine("Adding " + Path.GetFileNameWithoutExtension(proj.FullPath)); evaluatedProjects.Add(newProj); } } } catch (Exception e) { Console.WriteLine("Exception loading project " + ProjectPath + " exception " + e.Message); return; } } }
static int Main(string[] args) { Parser parser = new Parser(); if (!parser.ParseArguments(args, CommandLineOptions)) { Console.WriteLine(CommandLineOptions.GetUsage()); return(1); } if (string.IsNullOrEmpty(CommandLineOptions.Solution) && string.IsNullOrEmpty(CommandLineOptions.Project)) { Console.WriteLine("No vcxproj or sln provided: nothing to do!"); Console.WriteLine(CommandLineOptions.GetUsage()); return(1); } List <string> ProjectsToBuild = new List <string>(); if (!string.IsNullOrEmpty(CommandLineOptions.Solution) && File.Exists(CommandLineOptions.Solution)) { try { if (string.IsNullOrEmpty(CommandLineOptions.Project)) { List <ProjectInSolution> SolutionProjects = SolutionFile.Parse(Path.GetFullPath(CommandLineOptions.Solution)).ProjectsInOrder.Where(el => el.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat).ToList(); SolutionProjects.Sort((x, y) => //Very dubious sort. { if (x.Dependencies.Contains(y.ProjectGuid)) { return(1); } if (y.Dependencies.Contains(x.ProjectGuid)) { return(-1); } return(0); }); ProjectsToBuild = SolutionProjects.ConvertAll(el => el.AbsolutePath); } else { ProjectsToBuild.Add(Path.GetFullPath(CommandLineOptions.Project)); } SolutionDir = Path.GetDirectoryName(Path.GetFullPath(CommandLineOptions.Solution)); SolutionDir = SolutionDir.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); if (SolutionDir.Last() != Path.AltDirectorySeparatorChar) { SolutionDir += Path.AltDirectorySeparatorChar; } } catch (Exception e) { Console.WriteLine("Failed to load input file: " + CommandLineOptions.Solution + ", exception thrown was: " + e.Message); return(1); } } else if (!string.IsNullOrEmpty(CommandLineOptions.Project)) { ProjectsToBuild.Add(Path.GetFullPath(CommandLineOptions.Project)); } List <MSFBProject> EvaluatedProjects = new List <MSFBProject>(); for (int i = 0; i < ProjectsToBuild.Count; ++i) { EvaluateProjectReferences(ProjectsToBuild[i], EvaluatedProjects, null); } List <List <string> > build_list = new List <List <string> >(); System.Diagnostics.Stopwatch stop_watch = new System.Diagnostics.Stopwatch(); stop_watch.Start(); int ProjectsBuilt = 0; foreach (MSFBProject project in EvaluatedProjects) { CurrentProject = project; //MSBuild 15 (2017?) may not provide these properties. string VCTargetsPath = CurrentProject.Proj.GetPropertyValue("VCTargetsPath16"); if (string.IsNullOrEmpty(VCTargetsPath)) { VCTargetsPath = CurrentProject.Proj.GetPropertyValue("VCTargetsPath"); } if (string.IsNullOrEmpty(VCTargetsPath)) { VCTargetsPath = CurrentProject.Proj.GetPropertyValue("VCTargetsPathActual"); } if (string.IsNullOrEmpty(VCTargetsPath)) { Console.WriteLine("Failed to evaluate VCTargetsPath variable on " + Path.GetFileName(CurrentProject.Proj.FullPath) + ". Is this a supported version of Visual Studio?"); continue; } string BuildDllPath = VCTargetsPath + "Microsoft.Build.CPPTasks.Common.dll"; if (!File.Exists(BuildDllPath)) { Console.WriteLine("Failed to find " + BuildDllPath + ". Is this a supported version of Visual Studio?"); continue; } CPPTasksAssembly = Assembly.LoadFrom(BuildDllPath); BFFOutputFilePath = Path.GetDirectoryName(CurrentProject.Proj.FullPath) + "\\" + Path.GetFileName(CurrentProject.Proj.FullPath) + "_" + CommandLineOptions.Config.Replace(" ", "") + "_" + CommandLineOptions.Platform.Replace(" ", "") + ".bff"; GenerateBffFromVcxproj(CommandLineOptions.Config, CommandLineOptions.Platform); if (!CommandLineOptions.GenerateOnly) { if (HasCompileActions) { if (BuildOutput != BuildType.Application) { string FBArgs = Regex.Replace(CommandLineOptions.FBArgs, @"-j[0-9]*", ""); if (HasCompileActions && !ExecuteBffFile(CurrentProject.Proj.FullPath, CommandLineOptions.Platform, BFFOutputFilePath, FBArgs)) { break; } else { ProjectsBuilt++; } } else { var l = new List <string>(); l.Add(CurrentProject.Proj.FullPath); l.Add(CommandLineOptions.Platform); l.Add(BFFOutputFilePath); build_list.Add(l); } } } } List <System.Threading.Tasks.Task <bool> > list_threads = new List <System.Threading.Tasks.Task <bool> >(); foreach (var b_args in build_list) { list_threads.Add( System.Threading.Tasks.Task.Factory.StartNew(() => { return(ExecuteBffFile(b_args[0], b_args[1], b_args[2], CommandLineOptions.FBArgs)); }) ); } foreach (var t in list_threads) { t.Wait(); if (t.Result) { ++ProjectsBuilt; } } stop_watch.Stop(); TotalTime = stop_watch.Elapsed.TotalSeconds; UInt32 minutes = (UInt32)(TotalTime / 60.0f); TotalTime -= (minutes * 60.0f); double seconds = TotalTime; Console.WriteLine(""); if (minutes > 0) { Console.WriteLine("Total Time: " + minutes.ToString() + "m " + seconds.ToString("0.###") + "s"); } else { Console.WriteLine("Total Time: " + seconds.ToString("0.###") + "s"); } Console.WriteLine($"========== 빌드: 성공 {ProjectsBuilt}, 실패 {EvaluatedProjects.Count - ProjectsBuilt} =========="); if (ProjectsBuilt != EvaluatedProjects.Count) { return(1); } return(0); }
static void Main(string[] args) { Parser parser = new Parser(); if (!parser.ParseArguments(args, CommandLineOptions)) { Console.WriteLine(CommandLineOptions.GetUsage()); return; } if (string.IsNullOrEmpty(CommandLineOptions.Solution) && string.IsNullOrEmpty(CommandLineOptions.Project)) { Console.WriteLine("No vcxproj or sln provided: nothing to do!"); Console.WriteLine(CommandLineOptions.GetUsage()); return; } List <string> ProjectsToBuild = new List <string>(); if (!string.IsNullOrEmpty(CommandLineOptions.Solution) && File.Exists(CommandLineOptions.Solution)) { try { if (string.IsNullOrEmpty(CommandLineOptions.Project)) { List <ProjectInSolution> SolutionProjects = SolutionFile.Parse(Path.GetFullPath(CommandLineOptions.Solution)).ProjectsInOrder.Where(el => el.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat).ToList(); SolutionProjects.Sort((x, y) => //Very dubious sort. { if (x.Dependencies.Contains(y.ProjectGuid)) { return(1); } if (y.Dependencies.Contains(x.ProjectGuid)) { return(-1); } return(0); }); ProjectsToBuild = SolutionProjects.ConvertAll(el => el.AbsolutePath); } else { ProjectsToBuild.Add(Path.GetFullPath(CommandLineOptions.Project)); } SolutionDir = Path.GetDirectoryName(Path.GetFullPath(CommandLineOptions.Solution)); SolutionDir = SolutionDir.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); if (SolutionDir.Last() != Path.AltDirectorySeparatorChar) { SolutionDir += Path.AltDirectorySeparatorChar; } } catch (Exception e) { Console.WriteLine("Failed to load input file: " + CommandLineOptions.Solution + ", exception thrown was: " + e.Message); return; } } else if (!string.IsNullOrEmpty(CommandLineOptions.Project)) { ProjectsToBuild.Add(Path.GetFullPath(CommandLineOptions.Project)); } List <MSFBProject> EvaluatedProjects = new List <MSFBProject>(); for (int i = 0; i < ProjectsToBuild.Count; ++i) { EvaluateProjectReferences(ProjectsToBuild[i], EvaluatedProjects, null); } int ProjectsBuilt = 0; foreach (MSFBProject project in EvaluatedProjects) { CurrentProject = project; //MSBuild 15 (2017?) may not provide these properties. string VCTargetsPath = CurrentProject.Proj.GetPropertyValue("VCTargetsPath14"); if (string.IsNullOrEmpty(VCTargetsPath)) { VCTargetsPath = CurrentProject.Proj.GetPropertyValue("VCTargetsPath"); } if (string.IsNullOrEmpty(VCTargetsPath)) { VCTargetsPath = CurrentProject.Proj.GetPropertyValue("VCTargetsPathActual"); } if (string.IsNullOrEmpty(VCTargetsPath)) { Console.WriteLine("Failed to evaluate VCTargetsPath variable on " + Path.GetFileName(CurrentProject.Proj.FullPath) + ". Is this a supported version of Visual Studio?"); continue; } string BuildDllPath = VCTargetsPath + "Microsoft.Build.CPPTasks.Common.dll"; if (!File.Exists(BuildDllPath)) { Console.WriteLine("Failed to find " + BuildDllPath + ". Is this a supported version of Visual Studio?"); continue; } CPPTasksAssembly = Assembly.LoadFrom(BuildDllPath); BFFOutputFilePath = Path.GetDirectoryName(CurrentProject.Proj.FullPath) + "\\" + Path.GetFileName(CurrentProject.Proj.FullPath) + "_" + CommandLineOptions.Config.Replace(" ", "") + "_" + CommandLineOptions.Platform.Replace(" ", "") + ".bff"; GenerateBffFromVcxproj(CommandLineOptions.Config, CommandLineOptions.Platform); if (!CommandLineOptions.GenerateOnly) { if (HasCompileActions && !ExecuteBffFile(CurrentProject.Proj.FullPath, CommandLineOptions.Platform)) { break; } else { ProjectsBuilt++; } } } Console.WriteLine(ProjectsBuilt + "/" + EvaluatedProjects.Count + " built."); }
static void Main(string[] args) { Parser parser = new Parser(); if (!parser.ParseArguments(args, CommandLineOptions)) { Console.WriteLine(CommandLineOptions.GetUsage()); return; } if (string.IsNullOrEmpty(CommandLineOptions.Solution) && string.IsNullOrEmpty(CommandLineOptions.Project)) { Console.WriteLine("No solution or project provided!"); Console.WriteLine(CommandLineOptions.GetUsage()); return; } List <string> ProjectsToBuild = new List <string>(); if (!string.IsNullOrEmpty(CommandLineOptions.Solution) && File.Exists(CommandLineOptions.Solution)) { try { if (string.IsNullOrEmpty(CommandLineOptions.Project)) { List <ProjectInSolution> SolutionProjects = SolutionFile.Parse(Path.GetFullPath(CommandLineOptions.Solution)).ProjectsInOrder.Where(el => el.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat).ToList(); SolutionProjects.Sort((x, y) => //Very dubious sort. { if (x.Dependencies.Contains(y.ProjectGuid)) { return(1); } if (y.Dependencies.Contains(x.ProjectGuid)) { return(-1); } return(0); }); ProjectsToBuild = SolutionProjects.ConvertAll(el => el.AbsolutePath); } else { ProjectsToBuild.Add(Path.GetFullPath(CommandLineOptions.Project)); } SolutionDir = Path.GetDirectoryName(Path.GetFullPath(CommandLineOptions.Solution)); SolutionDir = SolutionDir.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); if (SolutionDir.Last() != Path.AltDirectorySeparatorChar) { SolutionDir += Path.AltDirectorySeparatorChar; } } catch (Exception e) { Console.WriteLine("Failed to parse solution file " + CommandLineOptions.Solution + "!"); Console.WriteLine("Exception: " + e.Message); return; } } else if (!string.IsNullOrEmpty(CommandLineOptions.Project)) { ProjectsToBuild.Add(Path.GetFullPath(CommandLineOptions.Project)); } List <MSFBProject> EvaluatedProjects = new List <MSFBProject>(); for (int i = 0; i < ProjectsToBuild.Count; ++i) { EvaluateProjectReferences(ProjectsToBuild[i], EvaluatedProjects, null); } int ProjectsBuilt = 0; foreach (MSFBProject project in EvaluatedProjects) { CurrentProject = project; string VCTargetsPath = CurrentProject.Proj.GetPropertyValue("VCTargetsPathEffective"); if (string.IsNullOrEmpty(VCTargetsPath)) { VCTargetsPath = CurrentProject.Proj.GetPropertyValue("VCTargetsPath"); } if (string.IsNullOrEmpty(VCTargetsPath)) { Console.WriteLine("Failed to evaluate VCTargetsPath variable on " + Path.GetFileName(CurrentProject.Proj.FullPath) + "!"); continue; } bool useBuiltinDll = true; string BuildDllName = "Microsoft.Build.CPPTasks.Common.dll"; string BuildDllPath = VCTargetsPath + BuildDllName; if (File.Exists(BuildDllPath)) { CPPTasksAssembly = Assembly.LoadFrom(BuildDllPath); if (CPPTasksAssembly.GetType("Microsoft.Build.CPPTasks.CL") != null && CPPTasksAssembly.GetType("Microsoft.Build.CPPTasks.RC") != null && CPPTasksAssembly.GetType("Microsoft.Build.CPPTasks.Link") != null && CPPTasksAssembly.GetType("Microsoft.Build.CPPTasks.LIB") != null) { useBuiltinDll = false; } } if (useBuiltinDll) { CPPTasksAssembly = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + BuildDllName); } BFFOutputFilePath = Path.GetDirectoryName(CurrentProject.Proj.FullPath) + "\\" + Path.GetFileName(CurrentProject.Proj.FullPath) + "_" + CommandLineOptions.Config.Replace(" ", "") + "_" + CommandLineOptions.Platform.Replace(" ", "") + ".bff"; GenerateBffFromVcxproj(CommandLineOptions.Config, CommandLineOptions.Platform); if (!CommandLineOptions.GenerateOnly) { if (HasCompileActions && !ExecuteBffFile(CurrentProject.Proj.FullPath, CommandLineOptions.Platform)) { break; } else { ProjectsBuilt++; } } } Console.WriteLine(ProjectsBuilt + "/" + EvaluatedProjects.Count + " built."); }