Exemple #1
0
        public VsVersions()
        {
            InitializeComponent();

            vsVersions = 0;

            VSVersion latest = 0, latestExpress = 0;

            for (VSVersion ver = VSVersion.VCSExpress; ver <= VSVersion.VisualStudio12; ver = (VSVersion)((uint)ver * 2u))
            {
                FromVSVersion(ver).IsEnabled = false;

                if ((canInstallVS & ver) == ver)
                {
                    vsVersions |= ver;
                    FromVSVersion(ver).IsEnabled = true;
                    latest = ver;
                    if (ver == VSVersion.VCSExpress || ver == VSVersion.WDExpress11 || ver == VSVersion.WDExpress12)
                    {
                        latestExpress = ver;
                    }
                }
            }

            if (latest != 0)
            {
                FromVSVersion(latest).IsChecked = true;
            }
            if (latestExpress != 0)
            {
                FromVSVersion(latestExpress).IsChecked = true;
            }
        }
Exemple #2
0
        public static void Run(string file, string args, VSVersion vs, MSBuildPlatform platform)
        {
            string msbuild = null;

            paths.Clear();
            if (vs == VSVersion.VS2019)
            {
                msbuild = VSPath("2019", _editions, "Current", platform);
                if (msbuild == null)
                {
                    msbuild = VSPath("2019", _editions, "16.0", platform);
                }
            }
            if (vs == VSVersion.VS2022)
            {
                msbuild = VSPath("2022", _editions, "Current", platform);
                if (msbuild == null)
                {
                    msbuild = VSPath("2022", _editions, "17.0", platform);
                }
            }

            if (msbuild == null)
            {
                foreach (var p in paths)
                {
                    Console.WriteLine("Tried: {0}", p);
                }
                throw new Exception($"Could not find installed MSBuild for {vs} {platform}");
            }

            RunCommand(msbuild, $"{Quote(file)} {args}");
        }
        private string GetProgIDForVSVersion(VSVersion vsVersion, VSSKU vsSKU)
        {
            string version = GetVersionString(vsVersion);
            string Sku     = GetSkuString(vsSKU);

            return(Sku + ".DTE." + version);
        }
Exemple #4
0
        private void RefreshSolutionInfo()
        {
            VSVersion currentSolutionVersion = (VSVersion)this.cbVersion.SelectedIndex;
            VSVersion newSolutionVersion     = currentSolutionVersion;

            string[] configurations = GetConfigurationsFromSolution(this.edtSolution.Text, ref newSolutionVersion);

            // Update the configurations list
            this.lstConfigurations.Items.Clear();
            foreach (string configuration in configurations)
            {
                // Make all the configurations initially enabled.
                ListViewItem item = new(configuration)
                {
                    Checked = true,
                };
                this.lstConfigurations.Items.Add(item);
            }

            // Update the version combo
            if (newSolutionVersion != currentSolutionVersion)
            {
                this.cbVersion.SelectedIndex = (int)newSolutionVersion;
            }
        }
Exemple #5
0
        CheckBox FromVSVersion(VSVersion version)
        {
            switch (version)
            {
            case VSVersion.VCSExpress:
                return(Cs10E);

            case VSVersion.VisualStudio10:
                return(Vs10);

            case VSVersion.WDExpress11:
                return(Wd11E);

            case VSVersion.VisualStudio11:
                return(Vs11);

            case VSVersion.WDExpress12:
                return(Wd12E);

            case VSVersion.VisualStudio12:
                return(Vs12);
            }

            throw new ArgumentOutOfRangeException("version");
        }
Exemple #6
0
        public VsVersions()
        {
            InitializeComponent();

            vsVersions = 0;

            VSVersion latest = 0, latestExpress = 0;
            for (VSVersion ver = VSVersion.VCSExpress; ver <= VSVersion.VisualStudio12; ver = (VSVersion)((uint)ver * 2u))
            {
                FromVSVersion(ver).IsEnabled = false;

                if ((canInstallVS & ver) == ver)
                {
                    vsVersions |= ver;
                    FromVSVersion(ver).IsEnabled = true;
                    latest = ver;
                    if (ver == VSVersion.VCSExpress || ver == VSVersion.WDExpress11 || ver == VSVersion.WDExpress12)
                        latestExpress = ver;
                }
            }

            if (latest != 0)
                FromVSVersion(latest).IsChecked = true;
            if (latestExpress != 0)
                FromVSVersion(latestExpress).IsChecked = true;
        }
 /// <summary>
 /// Launches VS with the specific version and SKU.
 /// </summary>
 /// <param name="VsVersion"></param>
 /// <param name="VsSKU"></param>
 public void LaunchVS(VSVersion VsVersion, VSSKU VsSKU)
 {
     if (!IsSkuInstalled(VsVersion, vsSKU))
     {
         throw new Exception(string.Format("The SKU with version {0} and SKU name {1} is not present in the machine. Please specify a different SKU or install it.", VsVersion, vsSKU));
     }
     this.vsVersion = VsVersion;
     this.vsSKU     = VsSKU;
     LaunchVSInternal();
 }
Exemple #8
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;
 }
Exemple #9
0
        /// <summary>
        /// Gets the Visual Studio version to be used.
        /// <para>
        /// If the user has specified the version than that version will be used.
        /// </para>
        /// If the user has specified Auto then we will determine VS's appropriate
        /// version based on the version of the file (.sln) we are going to build
        /// </summary>
        /// <param name="fileName">The name of the solution file to get the version (full path). Only used if <value>TfsBuildExtensions.Activities.VisualStudio.VSVersion.Auto</value> is specified</param>
        /// <param name="version">The version</param>
        /// <returns>The devenv version that will be used</returns>
        private static VSVersionInternal GetVersion(string fileName, VSVersion version)
        {
            if (version != VSVersion.Auto)
            {
                return((VSVersionInternal)(int)version);
            }

            var solution = new VSSolution(fileName);

            return(solution.FriendlyVersion);
        }
Exemple #10
0
        private async System.Threading.Tasks.Task InitializeCodeAnalysisSettingsAsync()
        {
            var codeAnalysisSettings = new CodeAnalysisSettingsFromOptionsPage(GeneralOptionsPage);

            GlobalCodeAnalysisSettings.InitializeGlobalSettingsOnce(codeAnalysisSettings);

            VSVersion = await VSVersionProvider.GetVersionAsync(this);

            SharedVsSettings.VSVersion = VSVersion;

            InitializeOutOfProcessSettingsSharing();
        }
        private void Initialize(string packagePath)
        {
            ZipPackage zipPackage = new ZipPackage(packagePath);

            packageId      = zipPackage.Id;
            packageVersion = zipPackage.Version.ToString();

            //set package sources.
            string PackageSource = Path.GetDirectoryName(packagePath);

            if (string.IsNullOrEmpty(PackageSource))
            {
                PackageSource = Environment.CurrentDirectory;
            }
            IList <KeyValuePair <string, string> > sources = new List <KeyValuePair <string, string> >();

            sources.Add(new KeyValuePair <string, string>("TestSource", PackageSource));
            //If additional sources are specified in the app.config file, add them too.
            if (!string.IsNullOrEmpty(AppSettingsHelper.PackageSourceKeyValue))
            {
                string[] additionalPackageSources = AppSettingsHelper.PackageSourceKeyValue.Split(new char[] { ',', ';' });
                int      i = 1;
                foreach (string additionalSource in additionalPackageSources)
                {
                    sources.Add(new KeyValuePair <string, string>("AdditionalSources_" + i.ToString(), additionalSource));
                    i++;
                }
            }
            NugetSettingsUtility.SetPackageSources(sources);
            NugetSettingsUtility.SetActivePackageSource("TestSource", PackageSource);

            //Set test run directory.
            if (string.IsNullOrEmpty(AppSettingsHelper.TestResultsPathKeyValue))
            {
                TestRunPath = Path.Combine(Environment.CurrentDirectory, packageId);
            }
            else
            {
                TestRunPath = AppSettingsHelper.TestResultsPathKeyValue;
            }
            //Create root level test run Dir
            if (!Directory.Exists(TestRunPath))
            {
                Directory.CreateDirectory(TestRunPath);
            }
            AppSettingsHelper.TestResultsPathKeyValue = TestRunPath;

            //initialize other values.
            projName  = DateTime.Now.Ticks.ToString();
            vsVersion = (VSVersion)Enum.Parse(typeof(VSVersion), AppSettingsHelper.VSVersionKeyValue, true);
            vsSKU     = (VSSKU)Enum.Parse(typeof(VSSKU), AppSettingsHelper.VSSKUKeyValue, true);
        }
 private void GetDefaultSKU(out VSVersion defaultVersion, out VSSKU defaultSku)
 {
     foreach (var version in Enum.GetValues(typeof(VSVersion)))
     {
         foreach (var sku in Enum.GetValues(typeof(VSSKU)))
         {
             if (IsSkuInstalled((VSVersion)version, (VSSKU)sku))
             {
                 defaultVersion = (VSVersion)version;
                 defaultSku     = (VSSKU)sku;
                 return;
             }
         }
     }
     throw new Exception("No VS SKU installed in this machine. Please make sure to install any SKU of VS to continue");
 }
Exemple #13
0
        public bool ClearRecentJumplist(VSVersion version, bool pinned, out string message)
        {
            bool result = false;

            message = string.Empty;
            try
            {
                VSBaseService service = GetVSService(version);
                result = service.ClearRecentJumpList(pinned, out message);
            }
            catch (Exception e)
            {
                message = e.Message;
            }

            return(result);
        }
        private string GetVersionString(VSVersion vsVersion)
        {
            switch (vsVersion)
            {
            case VSVersion.VS2013:
                return(VS2013VersionString);

            case VSVersion.VS2012:
                return(VS2012VersionString);

            case VSVersion.VS2010:
                return(VS2010VersionString);

            default:
                return(VS2012VersionString);
            }
        }
            public static string GetVSPath(VSVersion version)
            {
                if (version == VSVersion.Other)
                {
                    return(null);
                }
                string vsPath;

                if (version == VSVersion.VS2010)
                {
                    vsPath = GetVS2010Path();
                    if (!string.IsNullOrEmpty(vsPath))
                    {
                        return(vsPath);
                    }
                }
                return(GetVS2012Path());
            }
Exemple #16
0
        private VSBaseService GetVSService(VSVersion version)
        {
            VSBaseService service = null;

            switch (version)
            {
            case VSVersion.VS2015:
                service = new VS2015Service();
                break;

            case VSVersion.VS2017:
                service = new VS2017Service();
                break;

            default:
                break;
            }

            return(service);
        }
Exemple #17
0
        CheckBox FromVSVersion(VSVersion version)
        {
            switch (version)
            {
                case VSVersion.VCSExpress:
                    return Cs10E;
                case VSVersion.VisualStudio10:
                    return Vs10;
                case VSVersion.WDExpress11:
                    return Wd11E;
                case VSVersion.VisualStudio11:
                    return Vs11;
                case VSVersion.WDExpress12:
                    return Wd12E;
                case VSVersion.VisualStudio12:
                    return Vs12;
            }

            throw new ArgumentOutOfRangeException("version");
        }
Exemple #18
0
        private static string[] GetConfigurationsFromSolution(string solutionFile, ref VSVersion solutionVersion)
        {
            string[]? configurations = null;

            solutionFile = Manager.ExpandVariables(solutionFile);
            if (File.Exists(solutionFile))
            {
                string[] lines    = File.ReadAllLines(solutionFile);
                int      numLines = lines.Length;

                // We may have to look at lines 0 and 1.
                if (numLines >= 2)
                {
                    // In VS2005 Beta 2 the Unicode byte marks are on an otherwise blank
                    // first line, and the version string is on the second line.
                    string version = lines[0];
                    if (string.IsNullOrEmpty(version))
                    {
                        version = lines[1];
                    }

                    const string VersionLinePrefix = "Microsoft Visual Studio Solution File, Format Version ";
                    if (version.StartsWith(VersionLinePrefix))
                    {
                        version = version.Substring(VersionLinePrefix.Length).Trim();

                        // See if we support the solution version.
                        VSVersionInfo?versionInfo = GetSolutionVersion(version, lines);
                        if (versionInfo != null)
                        {
                            solutionVersion = versionInfo.Version;
                            configurations  = GetConfigurationsFromLines(lines);
                        }
                    }
                }
            }

            return(configurations ?? CollectionUtility.EmptyArray <string>());
        }
Exemple #19
0
        private static List <VSVersion> GetInstalledVsVersions()
        {
            List <VSVersion> versions = new List <VSVersion>();

            string[]  lines = GetVsWhereInfo("-sort");
            int       i     = 0;
            VSVersion version;

            while (i < lines.Length)
            {
                if (lines[i++].StartsWith("instanceId"))
                {
                    version = new VSVersion();
                    for (; i < lines.Length; i++)
                    {
                        string line = lines[i];
                        if (line.StartsWith("installationPath:"))
                        {
                            version.InstallationPath = line.Substring("installationPath:".Length).TrimStart();
                            int editionStart = version.InstallationPath.LastIndexOf('\\') + 1;
                            if (editionStart > 0)
                            {
                                version.Edition = version.InstallationPath.Substring(editionStart);
                                version.ShortInstallationPath = version.InstallationPath.Substring(0, editionStart - 1);
                            }
                            int versionStart = version.ShortInstallationPath.LastIndexOf('\\') + 1;
                            if (versionStart > 0)
                            {
                                version.Version = version.ShortInstallationPath.Substring(versionStart);
                            }
                            versions.Add(version);
                            break;
                        }
                    }
                }
            }
            return(versions);
        }
Exemple #20
0
 public ezBuildWinD(BuildMachineSettings settings, VSVersion version, bool bIs64Bit)
 {
     _settings = settings;
     _Version  = version;
     _bIs64Bit = bIs64Bit;
 }
        /// <summary>
        /// Gets the Visual Studio version to be used.
        /// <para>
        /// If the user has specified the version than that version will be used.
        /// </para>
        /// If the user has specified Auto then we will determine VS's appropriate
        /// version based on the version of the file (.sln) we are going to build
        /// </summary>
        /// <param name="fileName">The name of the solution file to get the version (full path). Only used if <value>TfsBuildExtensions.Activities.VisualStudio.VSVersion.Auto</value> is specified</param>
        /// <param name="version">The version</param>
        /// <returns>The devenv version that will be used</returns>
        private static VSVersionInternal GetVersion(string fileName, VSVersion version)
        {
            if (version != VSVersion.Auto)
            {
                return (VSVersionInternal)(int)version;
            }

            var solution = new VSSolution(fileName);
            return solution.FriendlyVersion;
        }
Exemple #22
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;
        }
Exemple #23
0
        public static Task <bool> Generate(string sourceDir, string destDir, bool x64, IProgress <string> progress, CancellationToken token)
        {
            return(Task.Run(() =>
            {
                string cMakeBinLoc = GetCMakeBinLocation();

                if (!Directory.Exists(cMakeBinLoc))
                {
                    return false;
                }

                string cmake = Path.Combine(cMakeBinLoc, "cmake.exe");

                if (!File.Exists(cmake))
                {
                    return false;
                }

                string args = String.Empty;

                VSVersion ver = VisualStudio.Version;

                if (x64)
                {
                    if (ver == VSVersion.VisualStudio12)
                    {
                        args = String.Format("/C \"\"{0}\" -G \"Visual Studio 12 Win64\" \"{1}\"\"", cmake, sourceDir);
                    }
                    else if (ver == VSVersion.VisualStudio11)
                    {
                        args = String.Format("/C \"\"{0}\" -G \"Visual Studio 11 Win64\" \"{1}\"\"", cmake, sourceDir);
                    }
                    else if (ver == VSVersion.VisualStudio10)
                    {
                        args = String.Format("/C \"\"{0}\" -G \"Visual Studio 10 Win64\" \"{1}\"\"", cmake, sourceDir);
                    }
                }
                else
                {
                    if (ver == VSVersion.VisualStudio12)
                    {
                        args = String.Format("/C \"\"{0}\" -G \"Visual Studio 12\" \"{1}\"\"", cmake, sourceDir);
                    }
                    else if (ver == VSVersion.VisualStudio11)
                    {
                        args = String.Format("/C \"\"{0}\" -G \"Visual Studio 11\" \"{1}\"\"", cmake, sourceDir);
                    }
                    else if (ver == VSVersion.VisualStudio10)
                    {
                        args = String.Format("/C \"\"{0}\" -G \"Visual Studio 10\" \"{1}\"\"", cmake, sourceDir);
                    }
                }

                if (!String.IsNullOrEmpty(args))
                {
                    var envPath = Environment.GetEnvironmentVariable("PATH");

                    if (envPath == null)
                    {
                        return false;
                    }

                    var envPathSplit = envPath.Split(';');


                    string gitLoc = TrinityCoreRepository.GetGitLocation();

                    if (string.IsNullOrEmpty(gitLoc))
                    {
                        return false;
                    }

                    gitLoc = gitLoc.Replace("git.exe", String.Empty);

                    var gitPath = envPathSplit.FirstOrDefault(p => p.Equals(gitLoc, StringComparison.OrdinalIgnoreCase));

                    var psi = new ProcessStartInfo("cmd.exe");

                    if (string.IsNullOrEmpty(gitPath))
                    {
                        psi.EnvironmentVariables["PATH"] = string.Format("{0};{1}", envPath, gitLoc);
                    }

                    psi.WorkingDirectory = destDir;

                    psi.UseShellExecute = false;

                    psi.CreateNoWindow = true;

                    psi.RedirectStandardOutput = true;
                    psi.RedirectStandardError = true;
                    psi.RedirectStandardInput = true;

                    psi.Arguments = args;

                    Process proc = ProcessHelper.StartProcess(psi);

                    if (proc == null)
                    {
                        return false;
                    }

                    int id = proc.Id;

                    proc.EnableRaisingEvents = true;

                    proc.BeginOutputReadLine();
                    proc.BeginErrorReadLine();

                    proc.OutputDataReceived += (sender, e) =>
                    {
                        progress.Report(e.Data);

                        if (token.IsCancellationRequested)
                        {
                            if (ProcessHelper.ProcessExists(id))
                            {
                                proc.Kill();
                                proc.Dispose();
                            }
                        }
                    };

                    proc.ErrorDataReceived += (sender, e) =>
                    {
                        progress.Report(e.Data);

                        if (token.IsCancellationRequested)
                        {
                            if (ProcessHelper.ProcessExists(id))
                            {
                                proc.Kill();
                                proc.Dispose();
                            }
                        }
                    };

                    proc.WaitForExit();

                    return true;
                }

                return false;
            }, token));
        }
Exemple #24
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;
        }
 public static string GetVSPath(VSVersion version) {
     if(version == VSVersion.Other) return null;
     string vsPath;
     if(version == VSVersion.VS2010) {
         vsPath = GetVS2010Path();
         if(!string.IsNullOrEmpty(vsPath)) return vsPath;
     }
     return GetVS2012Path();
 }
Exemple #26
0
        static void ParseArguments(string[] args)
        {
            // Make all string comparisons (and sort/order) invariant of current culture
            // Thus, solution output file is written in a consistent manner
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            string usage =
                @"CreateSolution 2.4 - Creates VS solution file.

Usage: CreateSolution [-g] [-vX] [-wWebSiteFolder] <path> <solutionfile> [excludeprojs...]

-g: Generate global sections (autogenerated by VS, required by msbuild).
-v0: Generate VS2010 sln file.
-v2: Generate VS2012 sln file.
-v3: Generate VS2013 sln file.
-v5: Generate VS2015 sln file.
-v7: Generate VS2017 sln file.
-v9: Generate VS2019 sln file (default).

Example: CreateSolution -wSites\WebSite1 -wSites\WebSite2 . all.sln myproj1 myproj2";

            bool          generateGlobalSection = false;
            VSVersion     vsVersion             = VSVersion.VS2019;
            List <string> websiteFolders        = new List <string>();

            List <string> argsWithoutFlags = new List <string>();

            foreach (string arg in args)
            {
                switch (arg)
                {
                case "-g":
                    generateGlobalSection = true;
                    break;

                case "-v0":
                    vsVersion = VSVersion.VS2010;
                    break;

                case "-v2":
                    vsVersion = VSVersion.VS2012;
                    break;

                case "-v3":
                    vsVersion = VSVersion.VS2013;
                    break;

                case "-v5":
                    vsVersion = VSVersion.VS2015;
                    break;

                case "-v7":
                    vsVersion = VSVersion.VS2017;
                    break;

                case "-v9":
                    vsVersion = VSVersion.VS2019;
                    break;

                default:
                    if (arg.StartsWith("-w"))
                    {
                        websiteFolders.Add(arg.Substring(2));
                    }
                    else
                    {
                        argsWithoutFlags.Add(arg);
                    }
                    break;
                }
            }

            if (argsWithoutFlags.Count < 2)
            {
                Console.WriteLine(usage);
                return;
            }


            string path            = argsWithoutFlags[0];
            string solutionfile    = argsWithoutFlags[1];
            var    excludeProjects = argsWithoutFlags.Skip(2).ToList();

            CreateSolution(path, solutionfile, generateGlobalSection, vsVersion, excludeProjects, websiteFolders);
        }
 private string GetSkuInstallRegKeyPath(VSVersion version, VSSKU sku)
 {
     return(Path.Combine(@"Software\Microsoft", GetSkuString(sku), GetVersionString(version), @"Setup\VS"));
 }
 private bool IsSkuInstalled(VSVersion version, VSSKU sku)
 {
     string[] subkeys = Registry.LocalMachine.OpenSubKey(GetSkuInstallRegKeyPath(version, sku)).GetSubKeyNames();
     return(subkeys != null && subkeys.Length > 0);
 }
Exemple #29
0
        public static VSVersionInfo GetInfo(VSVersion version)
        {
            VSVersionInfo result = VersionToInfoMap[version];

            return(result);
        }