コード例 #1
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);
        }
コード例 #2
0
        public bool Reload(out bool newRecent)
        {
            newRecent = false;
            if (!Source.Exists)
            {
                return(false);
            }
            Clear();
            EventLog.Inform(this, null, "Loading '" + Source.FullName + "'...");


            {
                var xreader = new XmlTextReader(Source.FullName);
                //int slashAt = Math.Max(file.FullName.LastIndexOf('/'), file.FullName.LastIndexOf('\\'));
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load(xreader);

                XmlNode xsolution = xdoc.SelectSingleNode("solution");
                XmlNode xDomain   = xsolution.Attributes.GetNamedItem("domain");

                if (xDomain != null)
                {
                    solutionDesc = new PersistentState.SolutionDescriptor(Source, xDomain.Value);
                }
                else
                {
                    solutionDesc = new PersistentState.SolutionDescriptor(Source, null);
                }


                newRecent = PersistentState.MemorizeRecent(solutionDesc);

                XmlNodeList xprojects = xdoc.SelectNodes("solution/project");

                foreach (XmlNode xproject in xprojects)
                {
                    Project.AddProjectReference(xproject, Source, this, null, true);
                }
                Directory.SetCurrentDirectory(Source.DirectoryName);
                xreader.Close();
            }

            Project p;

            while ((p = GetNextToLoad()) != null)
            {
                if (!p.HasSourceProject && !p.AutoConfigureSourcePath(Source))
                {
                    continue;
                }

                string filename = p.SourcePath.FullName;
                try
                {
                    var xreader = new XmlTextReader(filename);
                    try
                    {
                        XmlDocument xdoc = new XmlDocument();
                        xdoc.Load(xreader);
                        XmlNode xproject = xdoc.SelectSingleNode("project");
                        p.Load(xproject, this);
                    }
                    catch (Exception e)
                    {
                        EventLog.Warn(this, p, e.ToString());
                    }
                    xreader.Close();
                }
                catch (Exception e)
                {
                    EventLog.Warn(this, p, e.ToString());
                }
            }
            return(true);
        }