コード例 #1
0
ファイル: Solution.cs プロジェクト: nhab/vssolution
        // List of either String (line format is not intresting to us), or SolutionProject.

        /// <summary>
        /// Loads visual studio .sln solution
        /// </summary>
        /// <param name="solutionFileName"></param>
        /// <exception cref="System.IO.FileNotFoundException">The file specified in path was not found.</exception>
        public Solution(string solutionFileName)
        {
            slnLines = new List <object>();
            String slnTxt = File.ReadAllText(solutionFileName);

            string[] lines = slnTxt.Split('\n');
            //Match string like: Project("{66666666-7777-8888-9999-AAAAAAAAAAAA}") = "ProjectName", "projectpath.csproj", "{11111111-2222-3333-4444-555555555555}"
            Regex projMatcher =
                new Regex(
                    "Project\\(\"(?<ParentProjectGuid>{[A-F0-9-]+})\"\\) = \"(?<ProjectName>.*?)\", \"(?<RelativePath>.*?)\", \"(?<ProjectGuid>{[A-F0-9-]+})");

            Regex.Replace(slnTxt, "^(.*?)[\n\r]*$", new MatchEvaluator(m =>
            {
                String line = m.Groups[1].Value;

                Match m2 = projMatcher.Match(line);
                if (m2.Groups.Count < 2)
                {
                    slnLines.Add(line);
                    return("");
                }

                SolutionProject s = new SolutionProject();
                foreach (String g in projMatcher.GetGroupNames().Where(x => x != "0"))
                {
                    /* "0" - RegEx special kind of group */
                    s.GetType().GetField(g).SetValue(s, m2.Groups[g].ToString());
                }

                slnLines.Add(s);
                return("");
            }),
                          RegexOptions.Multiline
                          );
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: nhab/vssolution
        private void button1_Click(object sender, EventArgs e)
        {
            string str = "";

            try
            {
                OpenFileDialog ofd         = new OpenFileDialog();
                string         projectFile = "";
                ofd.Filter = "*.sln|*.sln;*.sln";
                if (ofd.ShowDialog() != DialogResult.Cancel)
                {
                    projectFile = ofd.FileName;
                }
                else
                {
                    return;
                }

                String   outProjectFile = Path.Combine(Path.GetDirectoryName(projectFile), Path.GetFileNameWithoutExtension(projectFile) + "_2.sln");
                Solution s = new Solution(projectFile);
                foreach (var proj in s.GetProjects())
                {
                    ListViewItem lvItm = new ListViewItem(proj.ProjectName);
                    ListViewItem.ListViewSubItem lvsub = new ListViewItem.ListViewSubItem();
                    lvsub.Text = proj.RelativePath;
                    ListViewItem.ListViewSubItem lvsub1 = new ListViewItem.ListViewSubItem();
                    lvsub1.Text = proj.ProjectGuid;
                    lvItm.SubItems.Add(lvsub);
                    lvItm.SubItems.Add(lvsub1);
                    listView1.Items.Add(lvItm);
                }

                SolutionProject p = s.GetProjects().Where(x => x.ProjectName.Contains("Plugin")).First();
                p.RelativePath = Path.Combine(Path.GetDirectoryName(p.RelativePath), Path.GetFileNameWithoutExtension(p.RelativePath) + "_Variation" + ".csproj");
                //textBox1.Text = str+"\r\n"+p.RelativePath;
                //  s.SaveAs(outProjectFile);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }