Beispiel #1
0
        public static Models.Solution Read(string filename)
        {
            System.IO.FileInfo fileInfo = new System.IO.FileInfo(filename);
            string             name     = fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length);

            System.IO.TextReader reader   = System.IO.File.OpenText(filename);
            Models.Solution      solution = Read(name, reader);
            reader.Close();
            return(solution);
        }
Beispiel #2
0
 private static bool HasVC(Models.Solution solution)
 {
     foreach (Models.Project project in solution.Projects)
     {
         if (project.Path.EndsWith(".vcproj"))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #3
0
        public void Build(string filename, string configuration)
        {
            System.IO.FileInfo fileInfo = new System.IO.FileInfo(filename);
            string             name     = fileInfo.Name.Substring(0, fileInfo.Name.ToLower().LastIndexOf(".sln"));

            System.IO.TextReader reader   = fileInfo.OpenText();
            Models.Solution      solution = SolutionReader.Read(filename, reader);
            reader.Close();

            string projectFolder = LastLeft(filename, System.IO.Path.DirectorySeparatorChar.ToString());

            this.Build(solution, configuration, projectFolder, String.Empty);
        }
Beispiel #4
0
        private static Models.Project LoadProject(string line, Models.Solution solution)
        {
            string[] sublines = line.Substring(line.IndexOf("=") + 1).Split(",".ToCharArray());
            string   name     = sublines[0].Trim().Substring(1, sublines[0].Trim().Length - 2);
            string   path     = sublines[1].Trim().Substring(1, sublines[1].Trim().Length - 2);

            System.Guid guid = new System.Guid(sublines[2].Trim().Substring(1, sublines[2].Trim().Length - 2));

            Models.Project project = new Models.Project();
            project.Name = name;
            project.Path = path;
            project.Guid = guid;
            return(project);
        }
Beispiel #5
0
        private static void LoadConfigurations(System.IO.TextReader reader, Models.Solution solution)
        {
            while (reader.Peek() != -1)
            {
                string line = reader.ReadLine();

                if (line.StartsWith("	EndGlobalSection"))
                {
                    return;
                }

                Models.Config config = new Models.Config();
                config.Name = line.Split("=".ToCharArray())[0].Trim();
                solution.Configs.Add(config);
            }
        }
Beispiel #6
0
        public static Models.Solution Read(string name, System.IO.TextReader reader)
        {
            Models.Solution solution = new Models.Solution();

            solution.Name = name;

            reader.ReadLine();
            while (reader.Peek() != -1)
            {
                string line = reader.ReadLine();

                if (line.StartsWith("Project"))
                {
                    Models.Project project = LoadProject(line, solution);
                    solution.Projects.Add(project);

                    line = reader.ReadLine();
                    if (line.Equals("	ProjectSection(ProjectDependencies) = postProject"))
                    {
                        line = reader.ReadLine();
                        while (!line.Equals("	EndProjectSection"))
                        {
                            string dependency = line.Split("=".ToCharArray())[0].Trim();
                            project.Dependencies.Add(new System.Guid(dependency));
                            line = reader.ReadLine();
                        }
                    }
                }
                else if (line.StartsWith("	GlobalSection(SolutionConfigurationPlatforms)"))
                {
                    LoadConfigurations(reader, solution);
                }
            }

            return(solution);
        }
Beispiel #7
0
        public static void Write(Models.Solution solution, System.IO.TextWriter writer)
        {
            if (!writer.Encoding.Equals(System.Text.Encoding.UTF8))
            {
                throw new System.Exception("Solution writer requires UTF8 encoding.");
            }
            System.Text.UTF8Encoding encoding = (System.Text.UTF8Encoding)writer.Encoding;
            byte[] bom = encoding.GetPreamble();
            if (bom.Length != 3 || bom[0] != 239 || bom[1] != 187 || bom[2] != 191)
            {
                throw new System.Exception("Solution writer requires UTF8 encoding with a Byte Order Mark.");
            }

            if (!HasVC(solution))
            {
                writer.WriteLine("");
            }
            writer.WriteLine("Microsoft Visual Studio Solution File, Format Version 10.00");
            writer.WriteLine("# Visual Studio 2008");
            foreach (Models.Project project in solution.Projects)
            {
                if (project.Path.EndsWith(".vcproj"))
                {
                    writer.WriteLine("Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"" + project.Name + "\", \"" + project.Path + "\", \"{" + project.Guid.ToString().ToUpper() + "}\"");
                    if (project.Dependencies.Count > 0)
                    {
                        writer.WriteLine("	ProjectSection(ProjectDependencies) = postProject");
                        foreach (System.Guid dependency in project.Dependencies)
                        {
                            writer.WriteLine("		{"+ dependency.ToString().ToUpper() + "} = {" + dependency.ToString().ToUpper() + "}");
                        }
                        writer.WriteLine("	EndProjectSection");
                    }
                    writer.WriteLine("EndProject");
                }
                else if (project.Path.EndsWith(".csproj"))
                {
                    writer.WriteLine("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"" + project.Name + "\", \"" + project.Path + "\", \"{" + project.Guid.ToString().ToUpper() + "}\"");
                    writer.WriteLine("EndProject");
                }
                else if (project.Path.EndsWith(".vbproj"))
                {
                    writer.WriteLine("Project(\"{F184B08F-C81C-45F6-A57F-5ABD9991F28F}\") = \"" + project.Name + "\", \"" + project.Path + "\", \"{" + project.Guid.ToString().ToUpper() + "}\"");
                    if (project.Dependencies.Count > 0)
                    {
                        writer.WriteLine("	ProjectSection(ProjectDependencies) = postProject");
                        foreach (System.Guid dependency in project.Dependencies)
                        {
                            writer.WriteLine("		{"+ dependency.ToString().ToUpper() + "} = {" + dependency.ToString().ToUpper() + "}");
                        }
                        writer.WriteLine("	EndProjectSection");
                    }
                    writer.WriteLine("EndProject");
                }
                else
                {
                    throw new System.Exception("Invalid project: " + project.Path);
                }
            }
            writer.WriteLine("Global");
            writer.WriteLine("	GlobalSection(SolutionConfigurationPlatforms) = preSolution");
            foreach (Models.Config config in solution.Configs)
            {
                writer.WriteLine("		"+ config.Name + " = " + config.Name + "");
            }
            writer.WriteLine("	EndGlobalSection");
            writer.WriteLine("	GlobalSection(ProjectConfigurationPlatforms) = postSolution");
            foreach (Models.Project project in solution.Projects)
            {
                foreach (Models.Config config in solution.Configs)
                {
                    writer.WriteLine("		{"+ project.Guid.ToString().ToUpper() + "}." + config.Name + ".ActiveCfg = " + config.Name + "");
                    writer.WriteLine("		{"+ project.Guid.ToString().ToUpper() + "}." + config.Name + ".Build.0 = " + config.Name + "");
                }
            }
            writer.WriteLine("	EndGlobalSection");
            writer.WriteLine("	GlobalSection(SolutionProperties) = preSolution");
            writer.WriteLine("		HideSolutionNode = FALSE");
            writer.WriteLine("	EndGlobalSection");
            writer.WriteLine("EndGlobal");

            writer.Flush();
        }