开发者

any msbuild file parsers available?

开发者 https://www.devze.com 2023-01-31 12:49 出处:网络
I am looking for an MSbuild file parser. Currently I have written my own that is not complete... but I feel li开发者_开发问答ke I am reinventing the wheel building something that surely exists already

I am looking for an MSbuild file parser. Currently I have written my own that is not complete... but I feel li开发者_开发问答ke I am reinventing the wheel building something that surely exists already.


Microsoft.Build.Construction.XXX in microsoft.build.dll (version 4.0+) is a "raw" parser of MSBuild files. It is powerful and complete and analogous to the XML DOM. It works on a single file, doing no evaluation. It's useful for example when you want to run a script over a tree of projects to edit them in some way, perhaps to add a common import statement.

Microsoft.Build.Evaluation.XXX works on evaluated projects -- ie., with all the properties evaluated, imported files pulled in and so forth. It's useful in a development environment - you can read off the files and properties in the project, add new files and so forth. Visual Studio uses it for this purpose.

Before 4.0, there was a completely different, much more limited, and less complete object model in microsoft.build.engine.dll. It still ships with 4.0 but cannot handle some 4.0 syntax. It is deprecated.

I designed and implemented these so I'd be interested in feedback if you have any.


Some info I have found here... http://social.msdn.microsoft.com/Forums/en/msbuild/thread/b3db4d7c-b7d1-4958-9145-bfd34cc75320

In addition there is a small projects with some highlevel samples: http://code.msdn.microsoft.com/msbuildho

using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        Project testProj = new Project();
        testProj.Xml.AddTarget("BuildProjects");
        foreach (ProjectTargetElement pti in testProj.Xml.Targets.Where(pti => pti.Name == "BuildProjects"))
        {
            pti.AddTask("MSBuild");   
        }   
        testProj.Save(@"C:\testProj.proj");
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号