gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 17:54:29 25 4
gpt4 key购买 nike

有没有办法列出 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);
}
}
}
}
}

关于visual-c++ - 列出可用的平台工具集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14447742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com