How to query MSBUILD file for list of supported targets?

后端 未结 6 441
遥遥无期
遥遥无期 2020-12-14 01:43

Is there any way to ask msbuild what build targets provided msbuild file support? If there is no way to do it in command prompt? May be it could be done programmatically?

6条回答
  •  执念已碎
    2020-12-14 02:32

    Certainly MS provides the api to do this without parsing the xml yourself. Look up microsoft.build.buildengine

    Adapted from some C# code found on msdn ... it's usually worth exploring. Need to reference the microsoft.build.engine dll for this to compile. Replace framework version and path below with your values. This worked on a sample project file, although the list may be longer than you expect.

    using System;
    using Microsoft.Build.BuildEngine;
    class MyTargets
    {        
      static void Main(string[] args)
      {
        Engine.GlobalEngine.BinPath = @"C:\Windows\Microsoft.NET\Framework\v2.0.NNNNN";
        Project project = new Project();
        project.Load(@"c:\path\to\my\project.proj");
        foreach (Target target in project.Targets)
        {
          Console.WriteLine("{0}", target.Name);
        }
      }
    }
    

提交回复
热议问题