Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query MSBUILD file for list of supported targets?

Tags:

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?

Are there no way to do it besides parsing msbuild XML?

like image 204
Artem Tikhomirov Avatar asked Jan 14 '09 01:01

Artem Tikhomirov


People also ask

What are MSBuild targets?

A target element can have both Inputs and Outputs attributes, indicating what items the target expects as input, and what items it produces as output. If all output items are up-to-date, MSBuild skips the target, which significantly improves the build speed. This is called an incremental build of the target.

What are target files C#?

Defines the steps in the standard build process for Visual Basic and C# projects. Defines the steps in the standard build process for Visual C# projects. Defines the steps in the standard build process for Visual Basic projects.

What is ItemGroup in MSBuild?

When multiple ItemGroup elements are used, items are combined into a single ItemGroup . For example, some items might be included by a separate ItemGroup element that's defined in an imported file. ItemGroups can have conditions applied by using the Condition attribute.

Will MSBuild compile a file without any target?

If MSBuild determines that any output files are out of date with respect to the corresponding input file or files, then MSBuild executes the target. Otherwise, MSBuild skips the target. After the target is executed or skipped, any other target that lists it in an AfterTargets attribute is run.


1 Answers

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);     }   } } 
like image 195
Zac Thompson Avatar answered Oct 10 '22 01:10

Zac Thompson