Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list available platform toolsets

Is there any method to list platform toolsets available in VS2012? I mean a list that might contain v90, v100, v110, v110_xp and any externally provided platform toolset. Alternatively (should that be easier): is there a way to check if given platform toolset is installed or not?

like image 682
Tomasz Grobelny Avatar asked Jan 21 '13 21:01

Tomasz Grobelny


People also ask

What is platform toolset in Visual Studio?

This platform toolset provides compatibility with the build options used in the WDK for Windows 7 (WDK 7.1). You might use this setting if you are migrating or converting a project that was built using WDK 7. Visual Studio 2012 (v110) Use for any type of Windows application (default).

How do I change my platform toolset?

To change the platform toolsetIn the properties page, select Platform Toolset and then select the toolset you want from the drop-down list. For example, if you've installed the Visual Studio 2010 toolset, select Visual Studio 2010 (v100) to use it for your project. Choose the OK button to save your changes.


1 Answers

Here is a console app utility (in C#) that dumps the list of toolset (for each available configuration). You need to add a reference to Microsoft.Build to be able to compile. Note the proper list of toolset is supposed to depend on the project to build:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace ListToolsets
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Format is ListToolsets <project file path>");
                return;
            }

            foreach (var toolset in PlatformToolset.GetPlatformToolsets(args[0]))
            {
                Console.WriteLine(toolset.Platform);
                foreach (string ts in toolset.Toolsets)
                {
                    Console.WriteLine(" " + ts);
                }
            }
        }

    }

    public class PlatformToolset
    {
        private PlatformToolset()
        {
            Toolsets = new List<string>();
        }

        public string Platform { get; private set; }
        public IList<string> Toolsets { get; private set; }

        public static IList<PlatformToolset> GetPlatformToolsets(string projectPath)
        {
            var list = new List<PlatformToolset>();
            var project = new Microsoft.Build.Evaluation.Project(projectPath);
            AddPlatformToolsets(project, @"$(VCTargetsPath14)\Platforms", list);
            AddPlatformToolsets(project, @"$(VCTargetsPath12)\Platforms", list);
            AddPlatformToolsets(project, @"$(VCTargetsPath11)\Platforms", list);
            AddPlatformToolsets(project, @"$(VCTargetsPath10)\Platforms", list);
            return list;
        }

        private static void AddPlatformToolsets(Microsoft.Build.Evaluation.Project project, string path, IList<PlatformToolset> list)
        {
            string platforms = Path.GetFullPath(project.ExpandString(path));
            if (!Directory.Exists(platforms))
                return;

            foreach (string platformPath in Directory.GetDirectories(platforms))
            {
                string platform = Path.GetFileName(platformPath);
                PlatformToolset ts = list.FirstOrDefault(t => t.Platform == platform);
                if (ts == null)
                {
                    ts = new PlatformToolset();
                    ts.Platform = platform;
                    list.Add(ts);
                }

                foreach (string toolset in Directory.GetDirectories(Path.Combine(platformPath, "PlatformToolsets")))
                {
                    string name = Path.GetFileName(toolset);
                    string friendlyName = project.GetPropertyValue("_PlatformToolsetFriendlyNameFor_" + name);
                    ts.Toolsets.Add(string.IsNullOrWhiteSpace(friendlyName) ? name : friendlyName);
                }
            }
        }
    }
}
like image 140
Simon Mourier Avatar answered Sep 20 '22 17:09

Simon Mourier