Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual c++ 列出可用的平台工具集_Visual C++_Visual Studio 2012_Msvcrt - Fatal编程技术网

Visual c++ 列出可用的平台工具集

Visual c++ 列出可用的平台工具集,visual-c++,visual-studio-2012,msvcrt,Visual C++,Visual Studio 2012,Msvcrt,是否有任何方法列出VS2012中可用的平台工具集?我指的是可能包含v90、v100、v110、v110_xp和任何外部提供的平台工具集的列表。或者(应该更容易):是否有方法检查给定的平台工具集是否已安装?这里有一个控制台应用程序实用程序(C#)用于转储工具集列表(对于每个可用配置)。您需要添加对Microsoft.Build的引用才能编译。注意,工具集的适当列表应取决于要构建的项目: using System; using System.Collections.Generic; using Sy

是否有任何方法列出VS2012中可用的平台工具集?我指的是可能包含v90、v100、v110、v110_xp和任何外部提供的平台工具集的列表。或者(应该更容易):是否有方法检查给定的平台工具集是否已安装?

这里有一个控制台应用程序实用程序(C#)用于转储工具集列表(对于每个可用配置)。您需要添加对Microsoft.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);
                }
            }
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.IO;
使用System.Linq;
名称空间列表工具集
{
班级计划
{
静态void Main(字符串[]参数)
{
如果(args.Length==0)
{
WriteLine(“格式为ListToolset”);
返回;
}
foreach(PlatformToolset.GetPlatformToolsets(args[0])中的var工具集)
{
控制台写入线(工具集平台);
foreach(toolset.Toolsets中的字符串ts)
{
控制台写入线(“+ts”);
}
}
}
}
公共类平台工具集
{
私有平台工具集()
{
工具集=新列表();
}
公共字符串平台{get;private set;}
公共IList工具集{get;private set;}
公共静态IList GetPlatformToolset(字符串项目路径)
{
var list=新列表();
var project=new Microsoft.Build.Evaluation.project(projectPath);
AddPlatformToolset(项目,@“$(VCTargetsPath14)\Platforms”,列表);
AddPlatformToolset(项目,@“$(VCTargetsPath12)\Platforms”,列表);
AddPlatformToolset(项目,@“$(VCTargetsPath11)\Platforms”,列表);
AddPlatformToolset(项目,@“$(VCTargetsPath10)\Platforms”,列表);
退货清单;
}
私有静态void AddPlatformToolsets(Microsoft.Build.Evaluation.Project项目,字符串路径,IList列表)
{
string platforms=Path.GetFullPath(project.ExpandString(Path));
如果(!Directory.Exists(platforms))
返回;
foreach(目录中的字符串platformPath.GetDirectories(platforms))
{
字符串platform=Path.GetFileName(platformPath);
PlatformToolset ts=list.FirstOrDefault(t=>t.Platform==Platform);
如果(ts==null)
{
ts=新平台工具集();
ts.平台=平台;
列表。添加(ts);
}
foreach(Directory.GetDirectories(Path.Combine(platformPath,“PlatformToolsets”))中的字符串工具集)
{
字符串名称=Path.GetFileName(工具集);
字符串friendlyName=project.GetPropertyValue(“\u PlatformToolsetFriendlyNameFor”+name);
添加(string.IsNullOrWhiteSpace(friendlyName)?名称:friendlyName);
}
}
}
}
}

我有一个C#程序来完成它,因为它依赖于.NET程序MsBuild。这是一个可以接受的答案吗?这个问题早就被遗忘了。。。我认为值得发布任何提示作为答案,即使它不是我(或Sneftel)可能想要使用的语言。就个人而言,我只想知道在磁盘上查找的位置,但在不调用MSBuild的情况下这样做可能是一个近似的过程。这似乎是一个好的方向。然而,这些VCTargetsPathXX似乎有点神奇。。。顺便说一句,添加VCTargetsPath12是检测v120(_xp)工具集所必需的。我的主要问题是:这会检测到第三方工具集还是只检测与VS一起交付的工具集。这里没有魔法。VCTargetsPathsXX是在msbuild目标文件(.targets或其他扩展名)中定义的,您可以在“…ProgramFiles\msbuild\…”中找到这些文件。您可以将其替换为本地VS安装路径。这将检测位于这些目录中的所有工具集。是的,但如何获取所有适用VCTargetsPathXX变量的列表?例如,在VS2014中,我需要添加VCTargetsPath13,或者他们如何称呼它。您在问题中要求添加VS2012。@Bishop-我不知道任何VS2014-抱歉挑剔:)但我已更新了支持VS2013的答案