示例#1
0
 private VSVersionInfo(VSVersion version, string?variable, decimal internalVersion, int solutionVersion, string?solutionCommentVersion = null)
 {
     this.Version                = version;
     this.ToolsVariable          = variable;
     this.InternalVersion        = internalVersion;
     this.SolutionVersion        = solutionVersion;
     this.DisplayNumber          = version.ToString().Substring(1);
     this.FullDisplayName        = "Visual Studio " + this.DisplayNumber;
     this.SolutionCommentVersion = solutionCommentVersion ?? this.FullDisplayName;
 }
示例#2
0
        static void CreateSolution(string path, string solutionfile, bool generateGlobalSection, VSVersion vsVersion, List <string> excludeProjects, List <string> websiteFolders)
        {
            List <string> files;

            string[] exts      = { ".csproj", ".vbproj", ".vcxproj", ".sqlproj", ".modelproj" };
            string[] typeguids =
            {
                "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC",  // maybe optional 9A19103F-16F7-4668-BE54-9A1E7A4F7556
                "F184B08F-C81C-45F6-A57F-5ABD9991F28F",
                "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942",
                "00D1A9C2-B5F0-4AF3-8072-F6C62B433612",
                "F088123C-0E9E-452A-89E6-6BA2F21D5CAC"
            };

            try
            {
                files = Directory.GetFiles(path, "*.*proj", SearchOption.AllDirectories)
                        .Where(filename => exts.Any(ext => Path.GetExtension(filename) == ext))
                        .ToList();
            }
            catch (DirectoryNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            foreach (string websiteFolder in websiteFolders)
            {
                if (!Directory.Exists(websiteFolder))
                {
                    Console.WriteLine($"Website folder doesn't exist: '{websiteFolder}'");
                    return;
                }
            }

            Console.WriteLine($"Generating solution for: {vsVersion.ToString()}");

            files.Sort();

            bool first = true;

            foreach (string filename in files.ToList())  // Create tmp list
            {
                if (excludeProjects.Any(p => exts.Any(ext => filename.EndsWith($"\\{p}{ext}"))))
                {
                    files.Remove(filename);
                    if (first)
                    {
                        Console.WriteLine("Excluding projects:");
                        first = false;
                    }
                    Console.WriteLine($"  '{filename}'");
                }
            }


            List <Proj> projs = GetProjects(files, solutionfile);


            projs = RemoveDups(projs);


            int projcount = 0;

            var sb = new StringBuilder();

            foreach (var p in projs.OrderBy(p => p.name))
            {
                for (int i = 0; i < exts.Length; i++)
                {
                    if (Path.GetExtension(p.path) == exts[i])
                    {
                        sb.AppendLine("Project(\"{" + typeguids[i] + "}\") = \"" + $"{p.name}\", \"{p.path}\", \"{{{p.guid}}}\"{Environment.NewLine}EndProject");
                    }
                }
                projcount++;
            }


            foreach (string websiteFolder in websiteFolders)
            {
                Random r    = new Random();
                int    port = r.Next(1024, 65535);

                sb.AppendLine(
                    "Project(\"{E24C65DC-7377-472B-9ABA-BC803B73C61A}\") = \"" + $"{Path.GetFileName(websiteFolder)}\", \"http://localhost:{port}\", \"" + "{" + Guid.NewGuid().ToString().ToUpper() + "}" + $"\"{Environment.NewLine}" +
                    $"\tProjectSection(WebsiteProperties) = preProject{Environment.NewLine}" +
                    $"\t\tSlnRelativePath = \"{websiteFolder}\\\"{Environment.NewLine}" +
                    $"\tEndProjectSection{Environment.NewLine}" +
                    $"EndProject");
            }



            if (projcount == 0)
            {
                Console.WriteLine($"Couldn't find any projects in: '{path}'");
                return;
            }


            if (generateGlobalSection)
            {
                sb.Append(GenerateGlobalSection(projs));
            }


            string s = sb.ToString();

            switch (vsVersion)
            {
            case VSVersion.VS2010:
                s = $"Microsoft Visual Studio Solution File, Format Version 11.00{Environment.NewLine}# Visual Studio 2010{Environment.NewLine}{s}";
                break;

            case VSVersion.VS2012:
                s = $"Microsoft Visual Studio Solution File, Format Version 12.00{Environment.NewLine}# Visual Studio 2012{Environment.NewLine}{s}";
                break;

            case VSVersion.VS2013:
                s = $"Microsoft Visual Studio Solution File, Format Version 12.00{Environment.NewLine}# Visual Studio 2013{Environment.NewLine}{s}";
                break;

            case VSVersion.VS2015:
                s = $"Microsoft Visual Studio Solution File, Format Version 12.00{Environment.NewLine}# Visual Studio 14{Environment.NewLine}{s}";
                break;

            case VSVersion.VS2017:
                s = $"Microsoft Visual Studio Solution File, Format Version 12.00{Environment.NewLine}# Visual Studio 15{Environment.NewLine}{s}";
                break;

            case VSVersion.VS2019:
                s = $"Microsoft Visual Studio Solution File, Format Version 12.00{Environment.NewLine}# Visual Studio Version 16{Environment.NewLine}{s}";
                break;
            }

            Console.WriteLine($"Writing {projcount} projects to {solutionfile}.");
            using (var sw = new StreamWriter(solutionfile))
            {
                sw.Write(s);
            }


            return;
        }
示例#3
0
        static void CreateSolution(string path, string solutionfile, bool generateGlobalSection, VSVersion vsVersion, List<string> excludeProjects, List<string> websiteFolders)
        {
            List<string> files;

            string[] exts = { ".csproj", ".vbproj", ".vcxproj", ".sqlproj", ".modelproj" };
            string[] typeguids = {
                "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC",
                "F184B08F-C81C-45F6-A57F-5ABD9991F28F",
                "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942",
                "00D1A9C2-B5F0-4AF3-8072-F6C62B433612",
                "F088123C-0E9E-452A-89E6-6BA2F21D5CAC" };

            try
            {
                files = Directory.GetFiles(path, "*.*proj", SearchOption.AllDirectories)
                    .Where(filename => exts.Any(ext => Path.GetExtension(filename) == ext))
                    .ToList();
            }
            catch (DirectoryNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            foreach (string websiteFolder in websiteFolders)
            {
                if (!Directory.Exists(websiteFolder))
                {
                    Console.WriteLine("Website folder doesn't exist: '" + websiteFolder + "'");
                    return;
                }
            }

            Console.WriteLine("Generating solution for: " + vsVersion.ToString());

            files.Sort();

            bool first = true;
            foreach (string filename in files.ToList())  // Create tmp list
            {
                if (excludeProjects.Any(p => exts.Any(ext => filename.EndsWith(@"\" + p + ext))))
                {
                    files.Remove(filename);
                    if (first)
                    {
                        Console.WriteLine("Excluding projects:");
                        first = false;
                    }
                    Console.WriteLine("  '" + filename + "'");
                }
            }

            List<proj> projs = GetProjects(files, solutionfile);

            projs = RemoveDups(projs);

            int projcount = 0;

            StringBuilder sb = new StringBuilder();

            foreach (proj p in projs.OrderBy(p => p.name))
            {
                for (int i = 0; i < exts.Length; i++)
                {
                    if (Path.GetExtension(p.path) == exts[i])
                    {
                        sb.AppendLine(
                            "Project(\"{" + typeguids[i] + "}\") = \"" + p.name + "\", \"" + p.path + "\", \"" + p.guid + "\"" + Environment.NewLine +
                            "EndProject");
                    }
                }
                projcount++;
            }

            foreach (string websiteFolder in websiteFolders)
            {
                Random r = new Random();
                int port = r.Next(1024, 65535);

                sb.AppendLine(
                    "Project(\"{E24C65DC-7377-472B-9ABA-BC803B73C61A}\") = \"" + Path.GetFileName(websiteFolder) + "\", \"http://localhost:" + port + "\", \"" + ("{" + Guid.NewGuid().ToString() + "}").ToUpper() + "\"" + Environment.NewLine +
                    "\tProjectSection(WebsiteProperties) = preProject" + Environment.NewLine +
                    //"\t\tDebug.AspNetCompiler.VirtualPath = \"/localhost_" + port + "\"" + Environment.NewLine +
                    //"\t\tDebug.AspNetCompiler.PhysicalPath = \"" + websiteFolder + "\\\"" + Environment.NewLine +
                    //"\t\tDebug.AspNetCompiler.TargetPath = \"PrecompiledWeb\\localhost_" + port + "\\\"" + Environment.NewLine +
                    //"\t\tRelease.AspNetCompiler.VirtualPath = \"/localhost_" + port + "\\\"" + Environment.NewLine +
                    //"\t\tRelease.AspNetCompiler.PhysicalPath = \"" + websiteFolder + "\\\"" + Environment.NewLine +
                    //"\t\tRelease.AspNetCompiler.TargetPath = \"PrecompiledWeb\\localhost_" + port + "\\\"" + Environment.NewLine +
                    "\t\tSlnRelativePath = \"" + websiteFolder + "\\\"" + Environment.NewLine +
                    "\tEndProjectSection" + Environment.NewLine +
                    "EndProject");
            }

            if (projcount == 0)
            {
                Console.WriteLine("Couldn't find any projects in: '" + path + "'");
                return;
            }

            if (generateGlobalSection)
            {
                sb.Append(GenerateGlobalSection(projs));
            }

            string s = sb.ToString();

            switch (vsVersion)
            {
                case VSVersion.VS2010:
                    s = "Microsoft Visual Studio Solution File, Format Version 11.00" + Environment.NewLine +
                        "# Visual Studio 2010" + Environment.NewLine +
                        s;
                    break;
                case VSVersion.VS2012:
                    s = "Microsoft Visual Studio Solution File, Format Version 12.00" + Environment.NewLine +
                        "# Visual Studio 2012" + Environment.NewLine +
                        s;
                    break;
                case VSVersion.VS2013:
                    s = "Microsoft Visual Studio Solution File, Format Version 12.00" + Environment.NewLine +
                        "# Visual Studio 2013" + Environment.NewLine +
                        s;
                    break;
                case VSVersion.VS2015:
                    s = "Microsoft Visual Studio Solution File, Format Version 12.00" + Environment.NewLine +
                        "# Visual Studio 14" + Environment.NewLine +
                        s;
                    break;
            }

            Console.WriteLine("Writing " + projcount + " projects to " + solutionfile + ".");
            using (StreamWriter sw = new StreamWriter(solutionfile))
            {
                sw.Write(s);
            }

            return;
        }