以编程方式读取构建配置 [英] Read build configurations programmatically

查看:91
本文介绍了以编程方式读取构建配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够以编程方式阅读VS构建配置.那是因为我要创建自己的生成器.

I want to be able to read the VS build configurations programmatically. That is because I want to create my own builder.

我该怎么做?有人有代码示例吗?

How do I do that? Does anyone have code example?

我的意思是,如果我具有Debug,Develop,Release,则希望它们在Form应用程序的列表框中列出.我已经尝试过使用"EnvDTE.dll"类,但是我不确定这是我要找的东西.如果有人能举一个具体的例子或链接到一个例子,我将不胜感激.

What i mean is that if I have Debug, Development, Release I want them to be listed in a list box in a Form application. I have tried using the "EnvDTE.dll" class but I am not sure it is what I am looking for. If anyone has a concrete example or link to an example I would be more than grateful.

推荐答案

您可以使用msbuild API.在Visual Studio 2015中,VS.2015附带的Microsoft.Build.dll中有一个名为Microsoft.Build.Construction.SolutionFile的类,可用于加载解决方案.

You can use the msbuild API. In Visual Studio 2015, there is a class called Microsoft.Build.Construction.SolutionFile in the Microsoft.Build.dll that ships with VS2015 that you can use to load a solution.

在VS2013中没有这样的东西,但是您可以执行以下操作: (参考Microsoft.Build.dll,Microsoft.Build.Engine.dll,Microsoft.Build.Framework.dll)

In VS2013 there is no such thing, but you can do the following: (reference Microsoft.Build.dll, Microsoft.Build.Engine.dll, Microsoft.Build.Framework.dll)

class Program
{
    static void Main(string[] args)
    {
        string nameOfSolutionForThisProject = @"MySolutionFile.sln";
        string wrapperContent = SolutionWrapperProject.Generate(nameOfSolutionForThisProject, toolsVersionOverride: null, projectBuildEventContext: null);
        byte[] rawWrapperContent = Encoding.Unicode.GetBytes(wrapperContent.ToCharArray());
        using (MemoryStream memStream = new MemoryStream(rawWrapperContent))
        using (XmlTextReader xmlReader = new XmlTextReader(memStream))
        {
            Project proj = ProjectCollection.GlobalProjectCollection.LoadProject(xmlReader);
            foreach (var p in proj.ConditionedProperties)
            {
                Console.WriteLine(p.Key);
                Console.WriteLine(string.Join(", ", p.Value));
            }
        }

        Console.ReadLine();
    }
}

ConditionedProperties包含解决方案中包含的平台和配置的列表.您可以使用它来填充表单.

ConditionedProperties contains a list of platforms and configurations contained in the solution. You can use this to populate your forms.

这篇关于以编程方式读取构建配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆