How do I access the current project context as part of a custom task?

How do I access the current project context as part of a custom task in MSBuild? At first it turned out that the GlobalProjectCollection link to the ProjectCollection would allow access, but it seems empty, at least when MSBuild starts from the command line.

Currently, I can get a new project instance based on the current project file as follows:

List projectAssemblies = new List();
using (XmlReader projectFileReader =
    XmlReader.Create(this.BuildEngine.ProjectFileOfTaskNode))
{
    Project project = new Project(projectFileReader);
    foreach (ProjectItem item in project.AllEvaluatedItems)
    {
      ... woo hoo ...
    }
}

but it seems like a lot of trouble. How can I access the project from which my task is being called?

+5
source share
1 answer

. MSBuild , , , . MSBuild, , , .

, , , , , . , ( ) , MSBuild .

+5

All Articles