Esempio n. 1
0
        public void Begin(IEnumerable <Solution> loadedSolutions, ToolsetVersion toolset, Action rebuildProjects)
        {
            this.toolset         = toolset;
            this.rebuildProjects = rebuildProjects;

            if (msBuildPath == "" && toolset.Path != null)
            {
                string[] segments = toolset.Path.Split(Path.DirectorySeparatorChar);
                if (FindBuildPath(string.Join(Path.DirectorySeparatorChar.ToString(), segments.Take(segments.Length - 2).ToArray())))
                {
                    LogEvent("Found MSBuild in " + msBuildPath);
                }
            }



            HashSet <Project> added = new HashSet <Project>();

            foreach (var s in loadedSolutions)
            {
                foreach (var p in s.Projects)
                {
                    //if (p.ReferencedBy.Count > 0)
                    //continue;
                    if (!added.Add(p))
                    {
                        continue;
                    }

                    if (IsPlatformAgnostic(p))
                    {
                        projects.Add(new JobID(Platform.None, p));
                    }
                    else
                    {
                        foreach (Platform platform in Solution.GetTargetPlatforms())
                        {
                            projects.Add(new JobID(platform, p));
                        }
                    }
                }
            }

            projects.Sort();



            buildConfigurations.Items.Clear();
            foreach (var cfg in Solution.GetPureBuildConfigurations())
            {
                buildConfigurations.Items.Add(cfg);
                if (cfg.Deploy)
                {
                    buildConfigurations.SelectedIndex = buildConfigurations.Items.Count - 1;
                }
            }

            ShowDialog();
        }
Esempio n. 2
0
        public bool Build(File outPath, ToolsetVersion toolset, bool overwriteExistingVSUserConfig)
        {
            EventLog.Inform(this, null, "Writing solution to '" + outPath.FullName + "'");

            //PersistentState.Toolset = toolSet.SelectedItem.ToString();

            DirectoryInfo dir = outPath.Directory;
            //DirectoryInfo projectDir = Directory.CreateDirectory(Path.Combine(dir.FullName, ".projects"));
            List <Tuple <File, Guid, Project> > projects = new List <Tuple <File, Guid, Project> >();

            var configurations = GetAllBuildConfigurations();

            //{
            //	new Configuration() {Name = "Debug", Platform = "Win32", IsRelease = false },
            //	new Configuration() {Name = "Debug", Platform = "x64", IsRelease = false },
            //	new Configuration() {Name = "Release", Platform = "Win32", IsRelease = true },
            //	new Configuration() {Name = "Release", Platform = "x64", IsRelease = true },
            //};


            foreach (Project p in localProjects)
            {
                var rs = p.SaveAs(toolset, configurations, overwriteExistingVSUserConfig, this);
                if (rs.Item3)
                {
                    EventLog.Inform(this, p, "Written to '" + rs.Item1.FullName + "'");
                }
                else
                {
                    EventLog.Inform(this, p, "No changes: '" + rs.Item1.FullName + "'");
                }
                projects.Add(new Tuple <File, Guid, Project>(rs.Item1, rs.Item2, p));
            }

            MemoryStream stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream, Encoding.UTF8);

            //File.CreateText(outPath.FullName);

            writer.WriteLine("Microsoft Visual Studio Solution File, Format Version 12.00");
            writer.WriteLine("# Visual Studio " + toolset);
            writer.WriteLine("VisualStudioVersion = " + toolset);
            writer.WriteLine("MinimumVisualStudioVersion = 10.0.40219.1");
            //Guid solutionGuid = Guid.NewGuid();
            string typeGUID = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942";               //C++. see http://www.codeproject.com/Reference/720512/List-of-Visual-Studio-Project-Type-GUIDs

            foreach (var tuple in projects)
            {
                string path = tuple.Item1.FullName;
                //Relativate(dir, tuple.Item1);
                writer.WriteLine("Project(\"{" + typeGUID + "}\") = \"" + tuple.Item3.Name + "\", \"" + path + "\", \"{"
                                 + tuple.Item2 + "}\"");
                writer.WriteLine("EndProject");
            }
            writer.WriteLine("Global");
            writer.WriteLine("\tGlobalSection(SolutionConfigurationPlatforms) = preSolution");
            foreach (var config in configurations)
            {
                writer.WriteLine("\t\t" + config + " = " + config + "");
            }
            writer.WriteLine("\tEndGlobalSection");
            writer.WriteLine("\tGlobalSection(ProjectConfigurationPlatforms) = postSolution");
            List <string> lines = new List <string>();

            foreach (var tuple in projects)
            {
                string guid = tuple.Item2.ToString().ToUpper();
                foreach (var config in configurations)
                {
                    lines.Add("\t\t{" + guid + "}." + config + ".ActiveCfg = " + config);
                    lines.Add("\t\t{" + guid + "}." + config + ".Build.0 = " + config);
                }
                //	writer.WriteLine("\t\t{" + guid + "}.Debug|Win32.ActiveCfg = Debug|Win32");
                //writer.WriteLine("\t\t{" + guid + "}.Debug|Win32.Build.0 = Debug|Win32");
                //writer.WriteLine("\t\t{" + guid + "}.Debug|x64.ActiveCfg = Debug|x64");
                //writer.WriteLine("\t\t{" + guid + "}.Debug|x64.Build.0 = Debug|x64");
                //writer.WriteLine("\t\t{" + guid + "}.Release|Win32.ActiveCfg = Release|Win32");
                //writer.WriteLine("\t\t{" + guid + "}.Release|Win32.Build.0 = Release|Win32");
                //writer.WriteLine("\t\t{" + guid + "}.Release|x64.ActiveCfg = Release|x64");
                //writer.WriteLine("\t\t{" + guid + "}.Release|x64.Build.0 = Release|x64");
            }
            lines.Sort();
            foreach (var line in lines)
            {
                writer.WriteLine(line);
            }
            writer.WriteLine("\tEndGlobalSection");

            writer.WriteLine("\tGlobalSection(SolutionProperties) = preSolution");
            writer.WriteLine("\t\tHideSolutionNode = FALSE");
            writer.WriteLine("\tEndGlobalSection");

            writer.WriteLine("EndGlobal");
            if (Program.ExportToDisk(outPath, writer))
            {
                EventLog.Inform(this, null, "Export done.");
            }
            else
            {
                EventLog.Inform(this, null, "No changes in .sln file. Skipping export.");
            }

            PersistentState.SetOutPathFor(Source, outPath);
            return(true);
        }