Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 766173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T17:00:12+00:00 2026-05-14T17:00:12+00:00

Given a build file (.csproj or msbuild.xml or whatever), I’d like to run a

  • 0

Given a build file (.csproj or msbuild.xml or whatever), I’d like to run a msbuild command that lists all the available, defined targets.

Does that function exist?

I know I could do an Xpath search or something, on the build file, but that wouldn’t find targets that are defined in included files.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T17:00:13+00:00Added an answer on May 14, 2026 at 5:00 pm

    Using MSBuild 2.0/3.5 : Custom Task

    You could write a custom msbuild task like this :

    using System;
    using System.Collections.Generic;
    using Microsoft.Build.BuildEngine;
    using Microsoft.Build.Framework;
    using Microsoft.Build.Utilities;
    
    namespace MSBuildTasks
    {
      public class GetAllTargets : Task
      {
        [Required]
        public String ProjectFile { get; set; }
    
        [Output]
        public ITaskItem[] Targets { get; set; }
    
        public override bool Execute()
        {
          var project = new Project(BuildEngine as Engine);
          project.Load(ProjectFile);
    
          var taskItems = new List<ITaskItem>(project.Targets.Count);
          foreach (Target target in project.Targets)
          {
            var metadata = new Dictionary<string, string>
                            {
                              {"Condition", target.Condition},
                              {"Inputs", target.Inputs},
                              {"Outputs", target.Outputs},
                              {"DependsOnTargets", target.DependsOnTargets}
                            };
            taskItems.Add(new TaskItem(target.Name, metadata));
          }
    
          Targets = taskItems.ToArray();
    
          return true;
        }
      }
    }
    

    That you’ll use like that:

    <Target Name="TestGetAllTargets">
      <GetAllTargets ProjectFile="$(MSBuildProjectFile)">
        <Output ItemName="TargetItems" TaskParameter="Targets"/>
      </GetAllTargets>
    
      <Message Text="Name: %(TargetItems.Identity) Input: %(TargetItems.Input) --> Output: %(TargetItems.Output)"/>
    </Target>
    

    Using MSBuild 4.0 : Inline task

    With MSBuild 4 you could use the new shiny thing : the inline task. Inline task allows you to define the behavior directly in msbuild file.

    <UsingTask TaskName="GetAllTargets"
               TaskFactory="CodeTaskFactory"
               AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
      <ParameterGroup>
        <ProjectFile ParameterType="System.String" Required="true"/>
        <TargetsOut ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true"/>
      </ParameterGroup>
      <Task>
        <Reference Include="System.Xml"/>
        <Reference Include="Microsoft.Build"/>
        <Reference Include="Microsoft.Build.Framework"/>
        <Using Namespace="Microsoft.Build.Evaluation"/>
        <Using Namespace="Microsoft.Build.Execution"/>
        <Using Namespace="Microsoft.Build.Utilities"/>
        <Using Namespace="Microsoft.Build.Framework"/>
        <Code Type="Fragment" Language="cs">
          <![CDATA[
            var project = new Project(ProjectFile);
            
            var taskItems = new List<ITaskItem>(project.Targets.Count);
            foreach (KeyValuePair<string, ProjectTargetInstance> kvp in project.Targets)
            {
              var target = kvp.Value;
              var metadata = new Dictionary<string, string>
                              {
                                {"Condition", target.Condition},
                                {"Inputs", target.Inputs},
                                {"Outputs", target.Outputs},
                                {"DependsOnTargets", target.DependsOnTargets}
                              };
              taskItems.Add(new TaskItem(kvp.Key, metadata));
            }
    
            TargetsOut = taskItems.ToArray();
          ]]>
        </Code>
      </Task>
    </UsingTask>
    
    <Target Name="Test">
      <GetAllTargets ProjectFile="$(MSBuildProjectFile)">
        <Output ItemName="TargetItems" TaskParameter="TargetsOut"/>  
      </GetAllTargets>
    
      <Message Text="%(TargetItems.Identity)"/>
    </Target>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been given an application which uses a build.xml file for building purposes.
I'm trying to build a script to retrieve all feed entries from a given
I am trying to send a simple XML file of the format given in
I have build a C++ class that accepts a file path and file pattern
I'd like to build a function, which, given a 2D matrix and some element
my build.XML is given below. <property name=src.dir value=src/> <property name=lib.dir value=lib/> <property name=build.dir value=build/>
I need to build a proxy (maybe a bad description) that receives an XML
Given a uncompressed input file with predefined frame format, need to build a simple
I'm looking to build a caching decorator that given a function caches the result
I would like to build an adaptor object which behaves like a (text) file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.